Results 1 to 5 of 5

Thread: [RESOLVED] Object Reference not set to an instance of object

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    5

    Resolved [RESOLVED] Object Reference not set to an instance of object

    Hi friends,
    This post is regarding deleting row in datagrid.

    code in datagrid1_deletedCommand


    1. dataSet11=new DataSet1();
    2. DataSet1.T_POTT_PROJECT_MASTERRow dr;
    3. long key=Convert.ToInt64(DataGrid1.DataKeys[e.Item.ItemIndex]);
    4. dr=this.dataSet11.T_POTT_PROJECT_MASTER.FindByPRJ_SL_NO(key);
    5. dr.Delete();
    6. oleDbDataAdapter1.Update(dataSet11);
    7. oleDbDataAdapter1.Fill(dataSet11);
    8. DataGrid1.DataBind();

    when i gone through the Debug mode i observed that dr is undefined value


    After Executing it is displaying
    System:NullReferenceException
    Object Reference not set to an instance of object


    Help me fast i just stucked................
    Thank in advance

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Object Reference not set to an instance of object

    If 'dr' is null after line 4 then there is no row with that key I would say, although I haven't worked with strongly typed DataSets much. Can I also suggest that you don't accept the default names for strongly typed DataSets. 'DataSet1' and 'dataSet11' are bad names.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    5

    Re: Object Reference not set to an instance of object

    Hi jmcilhinney,
    I have tried with other names also .But Error is repeated.

  4. #4
    Fanatic Member Slaine's Avatar
    Join Date
    Jul 2002
    Posts
    641

    Re: Object Reference not set to an instance of object

    I think jmcilhinney's advice on naming was just a general comment on good practice - it has little to do with the error.

    What he was saying (and I agree) is that if dr is null then it is because 'this.dataSet11.T_POTT_PROJECT_MASTER.FindByPRJ_SL_NO(key)' is not returning any rows. Have you checked that a row with the specified key does exist in the dataset?
    Martin J Wallace (Slaine)

  5. #5
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Object Reference not set to an instance of object

    I don't see where you are setting the DataSource property of the DatGrid. Generally it should look like this
    Code:
    DataGrid1.DataSource = datasetName;
    DataGrid1.DataMember = TableName;
    This should be enough to get you going.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width