Bij het verwijderen van een row in me datagrid krijg ik de volgende error:
Dit is de code wanneer er op de delete knop wordt gedrukt:
Weet iemand hoe ik het zo kan laten werken dat ik een row kan verwijderen uit mn datagrid?
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| Server Error in '/' Application.
--------------------------------------------------------------------------------
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Specified cast is not valid.
Source Error:
Line 119: private void DataGrid_Delete(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
Line 120: {
Line 121: string keyValue = (string)DGNieuws.DataKeys[e.Item.ItemIndex];
Line 122: string SQL = "DELETE FROM nieuws WHERE ID=" + keyValue;
Line 123: |
Dit is de code wanneer er op de delete knop wordt gedrukt:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| private void DataGrid_Delete(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string keyValue = (string)DGNieuws.DataKeys[e.Item.ItemIndex];
string SQL = "DELETE FROM nieuws WHERE ID=" + keyValue;
SqlConnection myConnection = new SqlConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Inetpub\\wwwroot\\bin\\marquette.mdb");
SqlCommand DeleteCommand = new SqlCommand(SQL, myConnection);
myConnection.Open();
DeleteCommand.ExecuteNonQuery();
myConnection.Close();
DGNieuws.CurrentPageIndex = 0;
DGNieuws.EditItemIndex = -1;
DataBind();
} |
Weet iemand hoe ik het zo kan laten werken dat ik een row kan verwijderen uit mn datagrid?