Hi Im trying to delete an item from the listbox which the user selects here you can find my code and a screenshot tnx.
Code:
public void deleteEvent(ListBox list_event)
{
int i = list_event.SelectedIndex;
ds.Tables["tblEvents"].Rows[i].Delete();
da.Update(ds.Tables["tblEvents"]);
}
Im getting Object reference not set to an instance of an object Exception.
ScreenShot: http://i53.tinypic.com/ad1209.jpg
Loading
VulpesPosted Apr 25, 2011, 12:56 PM
So are you saying that you didn't cater for it at all when you created the tblEvents DataTable in your DataSet? I was hoping that you had allowed for it but had called it something else.
Mark FenechPosted Apr 25, 2011, 11:37 AM
VulpesPosted Apr 25, 2011, 9:55 AM
Suppose, in the 'tblEvents' table in the database, you have a column called 'Member_ID'.
However, in the 'tblEvents' DataTable in the DataSet, you've called this column 'ID' instead.
When you create your DataAdapter, add these lines:
ITableMapping mapping = da.TableMappings.Add("Table", "tblEvents");
mapping.ColumnMappings.Add("Member_ID", "ID");
Now, when you update the database it should look for the "Table" mapping by default and (hopefully) all will be well.
VulpesPosted Apr 25, 2011, 6:19 AM
If you are, then either:
1. We'll need to create TableMappings for those columns, so that the Update() method can find them.
2. You'll need to change the names of those columns in the DataTable so that they're the same as the ones in the database.
Mark FenechPosted Apr 25, 2011, 6:00 AM
VulpesPosted Apr 25, 2011, 5:59 AM
da.Update(ds);
Mark FenechPosted Apr 25, 2011, 5:52 AM
public void deleteEvent(ListBox list_event)
{
int i = list_event.SelectedIndex;
ds.Tables["tblEvents"].Rows[i].Delete();
ds.AcceptChanges();
da.Update(ds.Tables["tblEvents"]);
}
VulpesPosted Apr 25, 2011, 5:20 AM
Mark FenechPosted Apr 24, 2011, 7:28 PM
http://i53.tinypic.com/n5kb9v.jpg
Help pls
Ankit NandekarPosted Apr 24, 2011, 2:09 PM
VulpesPosted Apr 24, 2011, 1:02 PM