I have gridview display columns from 2 tables
I need to edit & update record displayed in gridview
I wrote this code but it didn't work
Protected Sub GridView2_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView2.RowEditing
GridView2.EditIndex = e.NewEditIndex
GridView2.DataBind()
End Sub
The updating
Protected Sub GridView2_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView2.RowUpdating
' Dim connString As String = ConfigurationManager.ConnectionStrings("Conn").ConnectionString
Dim row As GridViewRow = DirectCast(GridView2.Rows(e.RowIndex), GridViewRow)
Dim lblupdate As Label = DirectCast(row.FindControl("Label2"), Label)
Dim id As String = DirectCast(GridView1.Rows(e.RowIndex).FindControl("lblid"), Label).Text
Dim stname As String = DirectCast(GridView1.Rows(e.RowIndex).FindControl("txtstname"), TextBox).Text
Dim dob As String = DirectCast(GridView1.Rows(e.RowIndex) _
.FindControl("txtdob"), TextBox).Text
Dim nationality As String = DirectCast(GridView1.Rows(e.RowIndex).FindControl("txtnationality"), TextBox).Text
Dim gender As String = DirectCast(GridView1.Rows(e.RowIndex).FindControl("txtgender"), TextBox).Text
Dim level As String = DirectCast(GridView1.Rows(e.RowIndex).FindControl("txtlevel"), TextBox).Text
Dim sect As String = DirectCast(GridView1.Rows(e.RowIndex).FindControl("txtsect"), TextBox).Text
Dim newst As String = DirectCast(GridView1.Rows(e.RowIndex).FindControl("txtnewst"), TextBox).Text
Dim con As New SqlConnection(strConnString)
Dim cmd As New SqlCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = "update stinfo set stname=@stname," _
& "dob=@dob, nationality=@nationality, gender=@gender,level=@level,sect=@sect,newst=@newst where id=@id"
cmd.Parameters.Add("@id", SqlDbType.NVarChar).Value = id
cmd.Parameters.Add("@stname", SqlDbType.NVarChar).Value = stname
cmd.Parameters.Add("@dob", SqlDbType.NChar).Value = dob
cmd.Parameters.Add("@nationality", SqlDbType.NChar).Value = nationality
cmd.Parameters.Add("@gender", SqlDbType.NVarChar).Value = gender
cmd.Parameters.Add("@level", SqlDbType.NVarChar).Value = level
cmd.Parameters.Add("@sect", SqlDbType.NChar).Value = sect
cmd.Parameters.Add("@newst", SqlDbType.NVarChar).Value = newst
cmd.ExecuteNonQuery()
GridView1.EditIndex = -1
'GridView1.DataSource = GetData(cmd)
GridView1.DataBind()
con.Close()
End Sub
where is the error comes from?