lorena
Centurion
I have a grid which should (in theory) allow the user to enter a new value for a field and write that value to the database. The record does not update when the user clicks "Update". I have the grid set so that the event is "dgRecs_UpdateRow" on the grid. I put a label on the form to show the values of the parameters being written and the parameter which should change, never does.
Here is my code:
Sub dgRecs_UpdateRow(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
Label2.Text = ""
If Not Page.IsValid Then Exit Sub
irecordID = dgRecs.DataKeys(e.Item.ItemIndex)
Dim Acc As TextBox = e.Item.Cells(12).Controls(0)
Dim objConn As OleDb.OleDbConnection
Dim objCommand As OleDb.OleDbCommand
objConn = New OleDb.OleDbConnection(strConnString)
objCommand = New OleDb.OleDbCommand(strSQL, objConn)
strSQL = "UPDATE [toolroom] " & _
" set [ACCEPT] = @accParam, " & _
" WHERE [REC_ID] = @recordIDParam "
Dim accParam As New OleDb.OleDbParameter("@accParam", OleDb.OleDbType.VarChar, 25)
accParam.Value = Acc.Text
objCommand.Parameters.Add(accParam)
'Record ID
Dim recordIDParam As New OleDb.OleDbParameter("@recordIDParam", OleDb.OleDbType.Single)
recordIDParam.Value = irecordID
objCommand.Parameters.Add(recordIDParam)
objConn.Open()
objCommand.ExecuteNonQuery()
Label2.Text = recordIDParam.Value & "," & accParam.Value
objConn.Close()
dgRecs.EditItemIndex = -1
ddlView.SelectedIndex = -1
BindData()
End Sub
I would REALLY appreciate some help with this. Thanks
Here is my code:
Sub dgRecs_UpdateRow(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
Label2.Text = ""
If Not Page.IsValid Then Exit Sub
irecordID = dgRecs.DataKeys(e.Item.ItemIndex)
Dim Acc As TextBox = e.Item.Cells(12).Controls(0)
Dim objConn As OleDb.OleDbConnection
Dim objCommand As OleDb.OleDbCommand
objConn = New OleDb.OleDbConnection(strConnString)
objCommand = New OleDb.OleDbCommand(strSQL, objConn)
strSQL = "UPDATE [toolroom] " & _
" set [ACCEPT] = @accParam, " & _
" WHERE [REC_ID] = @recordIDParam "
Dim accParam As New OleDb.OleDbParameter("@accParam", OleDb.OleDbType.VarChar, 25)
accParam.Value = Acc.Text
objCommand.Parameters.Add(accParam)
'Record ID
Dim recordIDParam As New OleDb.OleDbParameter("@recordIDParam", OleDb.OleDbType.Single)
recordIDParam.Value = irecordID
objCommand.Parameters.Add(recordIDParam)
objConn.Open()
objCommand.ExecuteNonQuery()
Label2.Text = recordIDParam.Value & "," & accParam.Value
objConn.Close()
dgRecs.EditItemIndex = -1
ddlView.SelectedIndex = -1
BindData()
End Sub
I would REALLY appreciate some help with this. Thanks