我是VB.NET程序员。我在ASP.NET中创建了一个包含3个字段的更新Web表单; ID
,Names
,Email
和3个按钮cmdUpdate
,cmdDelete
和cmdCancel
。除未执行的更新按钮外,其他所有命令都在执行,并且我也无法收到任何错误消息。代码如下。
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
我尝试研究和调整代码,但是数据库不会更新。请帮忙。谢谢。