|
Subject:
|
Deleting from a table
|
|
Posted By:
|
stu9820
|
Post Date:
|
9/23/2003 10:41:22 AM
|
I'm using an access db and trying to follow along with code for SQL Server.
This is the error message i'm getting:
No value given for one or more required parameters.
Line 65: objConn.Open() ----->Line 66: objCommand.ExecuteNonQuery() <------- Line 67: objConn.Close() on line 66.
Sub DBDelDataGrid_Delete(ByVal source As Object, ByVal E As DataGridCommandEventArgs) Dim objCommand As OleDbCommand Dim strSQLQuery As String
strSQLQuery = "DELETE FROM zNews WHERE id=" & dgNews.DataKeys(E.Item.ItemIndex) & ";"
'Response.Write(strSQLQuery) 'Response.End()
objCommand = New OleDbCommand(strSQLQuery, objConn)
objConn.Open() objCommand.ExecuteNonQuery() objConn.Close()
ShowDataGrid()
|
|
Reply By:
|
planoie
|
Reply Date:
|
9/23/2003 11:45:12 AM
|
My first thought is that this is not correct:
E.Item.ItemIndex
By this you are implying that the ID field of your database table is always going to align correctly with the ItemIndex generated by the datagrid for each item (row).
You need to specify where the data for the "ID" column comes from within the datagrid item. Usually you need something like this:
e.Item.Cells(<index of the ID column>).Text
The index of the ID column will be based on either your original SQL query that got the data for the bind to the data grid (when using AutoGenerateColumns) or the order you placed your columns in the <columns> section of the datagrid HTML.
Peter
|
|
Reply By:
|
stu9820
|
Reply Date:
|
9/23/2003 12:55:42 PM
|
Thanks Peter. Both ended up working after I found my error. I forgot that I changed the id column's name...
|