|
-
Feb 8th, 2006, 10:54 AM
#1
Thread Starter
New Member
[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
-
Feb 8th, 2006, 06:24 PM
#2
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.
-
Feb 9th, 2006, 12:33 AM
#3
Thread Starter
New Member
Re: Object Reference not set to an instance of object
Hi jmcilhinney,
I have tried with other names also .But Error is repeated.
-
Feb 9th, 2006, 06:26 AM
#4
Fanatic Member
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)
-
Feb 9th, 2006, 06:34 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|