RowUpdating is not functioning. The edit works. You can write into the highlighted row but when the update button is pressed it just reverts back to the original values in the database.
The datakeys may shed some light into this mystery but I do not know what they are or how to use them.
Sub ShowGrid() populates the gvedit Gridview from the database and functions correctly. Sample:
gvedit.EditIndex = Convert.ToInt32(ViewState("edit"))
gvedit.DataSource = dt
gvedit.DataBind()
Protected Sub gvedit_OnRowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) Handles gvedit.RowUpdating
Dim connStr, cmdStr As String
connStr = "connection string works"
cmdStr = "UPDATE test SET [datetime]=@datetime,[col1]=@col1,[col2]=@col2,[col3]=@col3 WHERE [idt]=@idt;"
Try
Using conn As New SqlConnection(connStr)
Using cmd As New SqlCommand(cmdStr, conn)
conn.Open()
cmd.Parameters.AddWithValue("@idt", GridView1.Rows(e.RowIndex).Cells(0).Text)
cmd.Parameters.AddWithValue("@datetime", DateTime.Now)
cmd.Parameters.AddWithValue("@col1", GridView1.Rows(e.RowIndex).Cells(2).Text)
cmd.Parameters.AddWithValue("@col2", GridView1.Rows(e.RowIndex).Cells(3).Text)
cmd.Parameters.AddWithValue("@col3", GridView1.Rows(e.RowIndex).Cells(4).Text)
cmd.ExecuteNonQuery()
conn.Close()
cmd.Dispose()
conn.Dispose()
End Using
End Using
Catch ex As Exception
TextBox1.Text = ex.Message
End Try
ViewState("edit") = e.RowIndex
ShowGrid()
End Sub
<asp:GridView ID="gvedit" runat="server" AutoGenerateColumns="True" AutoGenerateEditButton="True" OnRowCancelingEdit="gvedit_OnRowCancelingEdit" OnRowEditing="gvedit_OnRowEditing" OnRowUpdating="gvedit_OnRowUpdating"
<asp:GridView>