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开发者_StackOverflow Object reference not set to an instance of an object Exception.
ScreenShot:
- Make sure
ds
is not null. - Make sure there is a table called
tblEvents
in the data set,ds
. - Make sure the number of rows in the
tblEvents
is large enough so that the index you're using when deleting fits within the number of rows. - Make sure that the data adapter
da
is not null.
Without any further information, it's close to impossible to give any more insights.
精彩评论