Databind Error -- cannot figure out why.

R

Rathtap

I get the following error on Line 49 (UG1.DataBind()) only if the
Select Stored procedure returns no records. I am using a dataadapter
and a dataset and binding the datagrid to the dataset. If there is
even one record my grid populates perfectly.

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

Source Error:

Line 46:populateDataSet();
Line 47:UG1.DisplayLayout.AllowUpdateDefault=AllowUpdate.Yes;
Line 48:UG1.DataSource=dsetAPC1.Tables[ParentTable].DefaultView;
Line 49:UG1.DataBind();
Line 50:
Line 51:



private void populateDataSet()
{
Cnn.ConnectionString =
ConfigurationSettings.AppSettings["ConnectionString"];
sqlSelectCommand1.Parameters["@payer_id"].Value = payer_id;
daAPC1.SelectCommand=sqlSelectCommand1;
daAPC1.MissingSchemaAction = MissingSchemaAction.AddWithKey;
daAPC1.Fill(dsetAPC1,ParentTable);
UG1.Bands[0].DataKeyField=dsetAPC1.Tables[ParentTable].PrimaryKey[0].ColumnName
+ "," + dsetAPC1.Tables[ParentTable].PrimaryKey[1].ColumnName;
}
 
A

Alvin Bruney

you need to be checking this for null first before binding
dsetAPC1.Tables[ParentTable].DefaultView != null
then set to data source and bind
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top