Updating a datgrid through an EditColumn command
Hello everyone,
I was hopiung you would be able to help me in updating a Data Grid. Basically I want to have a datagrid with an EditColumn. Once the user edits their row in the Datagrid, they can update the database. I've put together some code for this but I am missing something. Can you please help me find out what it is? I think the error is in this line:
CatagoryParam.Value = e.item.itemindex
thanks,
Ray
Sub DataGrid1_Update(Sender As Object, e As DataGridCommandEventArgs)
Dim connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\BegASPNet11\mydatabase.mdb"
Dim dbConnection as New OledbConnection(connectionString) dbConnection.open()
Dim dbcommandString as String = "INSERT INTO MyCatalogue (Catagory, ProductName) " & _
"VALUES(@Catagory, @ProductName)"
Dim dbCommand as new OleDbCommand(dbCommandString, dbConnection)
Dim CatagoryParam as New OleDbParameter ("@Catagory", OleDbType.VarChar)
CatagoryParam.Value = e.item.itemindex
dbCommand.Parameters.Add(CatagoryParam)
Dim ProductNameParam as New OleDbParameter("@ProductName", OleDbType.VarChar)
ProductNameParam.Value = e.item.itemindex
dbCommand.Parameters.Add(ProductNameParam)
dbCommand.ExecuteNonQuery()
DataGrid1.DataBind()
dbConnection.Close()
End Sub
|