Here we will see how to update your database.In this section we will update name of student using Roll no attribute.Use same form just replace delete button with update button and add one more textbox where you will enter name of student which you want to save in database.
Now double click update button.Type following code in button click event of update button.
Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("a").ToString())
Dim sqlqry As String = "update Table1 set Name=' " & txt4.Text & " 'where Rollno=' " & txt5.Text & " '"
Dim cmd As SqlCommand
Try
connection.Open()
cmd = New SqlCommand(sqlqry, connection)
cmd.ExecuteNonQuery()
Catch ex As Exception
lblmsg.Text = ex.Message
Finally
connection.Close()
End Try
Initially consider following entry were there in database.
Now save and run your website.
Now see following screenshot shows you updated database.
Now double click update button.Type following code in button click event of update button.
Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("a").ToString())
Dim sqlqry As String = "update Table1 set Name=' " & txt4.Text & " 'where Rollno=' " & txt5.Text & " '"
Dim cmd As SqlCommand
Try
connection.Open()
cmd = New SqlCommand(sqlqry, connection)
cmd.ExecuteNonQuery()
Catch ex As Exception
lblmsg.Text = ex.Message
Finally
connection.Close()
End Try
Initially consider following entry were there in database.
Now save and run your website.
Now see following screenshot shows you updated database.
No comments:
Post a Comment