Hi Team,
Am using Grid View in ASP.Net while am trying to update the row it was not getting updated. Instead, it throw an exception Object reference not set to an instance. please help me in this regard.
Am using Grid View in ASP.Net while am trying to update the row it was not getting updated. Instead, it throw an exception Object reference not set to an instance. please help me in this regard.
Code:
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Try
Dim txtName, txtName1, txtName2, txtname3 As New TextBox
Dim row As GridViewRow = GridView1.Rows(e.RowIndex)
txtName = CType(row.FindControl("txtName"), TextBox)
txtName1 = CType(row.FindControl("txtName1"), TextBox)
txtName2 = CType(row.FindControl("txtName2"), TextBox)
txtname3 = CType(row.FindControl("txtName3"), TextBox)
'doupdate(txtName1, txtName2, txtname3, txtName)
'con.Open()
cmd = New MySqlCommand("update login set username='" & txtName1.Text & "',password='" & txtName2.Text & "',Usertype='" & txtname3.Text & "' where id='" & txtName.Text & "')", con)
da = New MySqlDataAdapter(cmd)
cmd.ExecuteNonQuery()
ds = New DataSet
da.Fill(ds)
GridView1.DataSource = ds
GridView1.DataBind()
con.Close()
Catch ex As Exception
msgbox(ex.Message.ToString)
End Try
End Sub
Comment