M
MrMike
Hi. I have a datagrid UpdateCommand event that is supposed to identify
record changes during an edit process and resolve those changes back to a SQL
database.
The code below is supposed to identify any changes made to the 16th column
of the datagrid and update the database. However, when I click the Edit
hyperlink, make a change to the 16th column, and then click UPDATE the page
will refresh but no changes are saved. No changes are made and the data is
back to it's original value.
------------------------------------------
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
Handles DataGrid1.UpdateCommand
Dim DDL As DropDownList = _
CType(e.Item.Cells(15).Controls(1), DropDownList)
Dim NewSpecie As Integer = DDL.SelectedValue
Dim FlitchNum As String = e.Item.Cells(1).Text
Dim SQL As String = _
"UPDATE tblLogs SET SpecieID=@SelectSpecie WHERE FlitchNum=@ID"
Dim ConnStr As String
ConnStr = "workstation id=LAPTOP;packet size=4096;integrated
security=SSPI;data source=sjserver1;persist security info=False;initial
catalog=dbname"
Dim Conn As SqlConnection = New SqlConnection(ConnStr)
Dim Cmd As New SqlCommand(SQL, Conn)
Cmd.Parameters.Add(New SqlParameter("@SelectSpecie", NewSpecie))
Cmd.Parameters.Add(New SqlParameter("@ID", FlitchNum))
Conn.Open()
Cmd.ExecuteNonQuery()
Conn.Close()
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
record changes during an edit process and resolve those changes back to a SQL
database.
The code below is supposed to identify any changes made to the 16th column
of the datagrid and update the database. However, when I click the Edit
hyperlink, make a change to the 16th column, and then click UPDATE the page
will refresh but no changes are saved. No changes are made and the data is
back to it's original value.
------------------------------------------
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
Handles DataGrid1.UpdateCommand
Dim DDL As DropDownList = _
CType(e.Item.Cells(15).Controls(1), DropDownList)
Dim NewSpecie As Integer = DDL.SelectedValue
Dim FlitchNum As String = e.Item.Cells(1).Text
Dim SQL As String = _
"UPDATE tblLogs SET SpecieID=@SelectSpecie WHERE FlitchNum=@ID"
Dim ConnStr As String
ConnStr = "workstation id=LAPTOP;packet size=4096;integrated
security=SSPI;data source=sjserver1;persist security info=False;initial
catalog=dbname"
Dim Conn As SqlConnection = New SqlConnection(ConnStr)
Dim Cmd As New SqlCommand(SQL, Conn)
Cmd.Parameters.Add(New SqlParameter("@SelectSpecie", NewSpecie))
Cmd.Parameters.Add(New SqlParameter("@ID", FlitchNum))
Conn.Open()
Cmd.ExecuteNonQuery()
Conn.Close()
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()