Databind Error -- cannot figure out why.

Discussion in 'ASP .Net Datagrid Control' started by Rathtap, Sep 8, 2003.

  1. Rathtap

    Rathtap Guest

    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;
    }
     
    Rathtap, Sep 8, 2003
    #1
    1. Advertising

  2. Rathtap

    Alvin Bruney Guest

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

    "Rathtap" <> wrote in message
    news:...
    > 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].ColumnN
    ame
    > + "," + dsetAPC1.Tables[ParentTable].PrimaryKey[1].ColumnName;
    > }
     
    Alvin Bruney, Sep 15, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,131
    Smokey Grindel
    Dec 2, 2006
  2. mieskola
    Replies:
    1
    Views:
    329
    mlimber
    Aug 16, 2006
  3. cucuzza15
    Replies:
    0
    Views:
    255
    cucuzza15
    Oct 22, 2008
  4. Jack

    Cannot figure out error in asp code

    Jack, Jul 25, 2004, in forum: ASP General
    Replies:
    2
    Views:
    199
    Bã§TãRÐ
    Jul 27, 2004
  5. ApathyBear
    Replies:
    9
    Views:
    96
    Dave Angel
    Feb 20, 2014
Loading...

Share This Page