I'm a VB.NET programmer. I have created an update web form in ASP.NET having 3 fields; ID
, Names
, Email
with 3 buttons cmdUpdate
, cmdDelete
and cmdCancel
. All are executing except for the update button which is not executing, and I can't get an error message either. The code is below.
Protected Sub cmdUpdate_Click(sender As Object, e As EventArgs) Handles cmdUpdate.Click
Dim conn As New SqlClient.SqlConnection("Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=RegDb_backend;Integrated security=true;")
Dim sql As String = "UPDATE tblClients SET ClientNames=@Names, ClientEmail=@Email WHERE ClientID=@ID;"
Dim cmd = New SqlClient.SqlCommand(sql, conn)
cmd.Parameters.Add(New SqlParameter("@Names", txtNames.Text.Trim()))
cmd.Parameters.Add(New SqlParameter("@Email", txtEmail.Text.Trim()))
cmd.Parameters.Add(New SqlParameter("@ID", Convert.ToInt64(txtID.Text.Trim)))
Try
conn.Open()
cmd.ExecuteNonQuery()
lblSuccess.Visible = True
conn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
I have tried researching and tweaking around with the code but the database won't get updated. Please help. Thank you.