M
Mico
I would be very grateful for any help with the following problem:
I use a DataAdapter to fill a DataSet in the Page_Load method.
Later, I use this DataSet to construct a DataTable, then create a
DataRow and search through the DataTable for a specific row. Having
found the row, I intend to display the various fields in some text
boxes. This is all triggered from a dropdownlist. The code for this
is shown below:
private void ddlTerms_SelectedIndexChanged(object sender,
System.EventArgs e)
{
DataTable tblTerm = dsAllTerm.Tables["tblTerm"];
DataRow drCurrent = tblTerm.Rows.Find(ddlTerms.SelectedValue);
txtName.Text = drCurrent["Term Name"].ToString();
}
However, when I load the page and trigger the relevant event, I get
the following message:
"Object reference not set to an instance of an object.
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object."
The stack trace indicates this is a problem from the following line:
txtName.Text = drCurrent["Term Name"].ToString();
I think I've narrowed it down to the fact that drCurrent is giving a
null reference, but I don't know why or how to fix it.
Can anyone help?
Thanks,
Mark.
I use a DataAdapter to fill a DataSet in the Page_Load method.
Later, I use this DataSet to construct a DataTable, then create a
DataRow and search through the DataTable for a specific row. Having
found the row, I intend to display the various fields in some text
boxes. This is all triggered from a dropdownlist. The code for this
is shown below:
private void ddlTerms_SelectedIndexChanged(object sender,
System.EventArgs e)
{
DataTable tblTerm = dsAllTerm.Tables["tblTerm"];
DataRow drCurrent = tblTerm.Rows.Find(ddlTerms.SelectedValue);
txtName.Text = drCurrent["Term Name"].ToString();
}
However, when I load the page and trigger the relevant event, I get
the following message:
"Object reference not set to an instance of an object.
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object."
The stack trace indicates this is a problem from the following line:
txtName.Text = drCurrent["Term Name"].ToString();
I think I've narrowed it down to the fact that drCurrent is giving a
null reference, but I don't know why or how to fix it.
Can anyone help?
Thanks,
Mark.