[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
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.
Re: Object Reference not set to an instance of object
Hi jmcilhinney,
I have tried with other names also .But Error is repeated.
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?
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.