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

VulpesRank #55 · 29.2K reputationPosted Apr 24, 2011, 9:02 AM EDT
Ankit NandekarRank #703 · 3.4K reputationPosted Apr 24, 2011, 10:09 AM EDT
Mark Fenech81 reputationPosted Apr 24, 2011, 3:28 PM EDT
http://i53.tinypic.com/n5kb9v.jpg
Help pls
VulpesRank #55 · 29.2K reputationPosted Apr 25, 2011, 1:20 AM EDT
Mark Fenech81 reputationPosted Apr 25, 2011, 1:52 AM EDT
public void deleteEvent(ListBox list_event)
{
int i = list_event.SelectedIndex;
ds.Tables["tblEvents"].Rows[i].Delete();
ds.AcceptChanges();
da.Update(ds.Tables["tblEvents"]);
}
VulpesRank #55 · 29.2K reputationPosted Apr 25, 2011, 1:59 AM EDT
da.Update(ds);
Mark Fenech81 reputationPosted Apr 25, 2011, 2:00 AM EDT
VulpesRank #55 · 29.2K reputationPosted Apr 25, 2011, 2:19 AM EDT
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.
VulpesRank #55 · 29.2K reputationPosted Apr 25, 2011, 5:55 AM EDT
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.
Mark Fenech81 reputationPosted Apr 25, 2011, 7:37 AM EDT
VulpesRank #55 · 29.2K reputationPosted Apr 25, 2011, 8:56 AM EDT
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.