我正在使用 asp.net vb.net 和 SQL Server 编写一个教育网站。我有 4 个堆栈持有者,如果任何人登录他的个人资料,他会看到他的信息
如果他想更新它们,他只需更改文本框,然后单击更新
我的问题是如何更新。
我写了一个更新方法,但它总是在查询中显示语法错误。我确定没有问题。我正在更新两个表,并制作了 sql 语句!
我的问题是我可以插入而不是更新吗?
如果不是:如何根据我拥有的会话更新一条记录?
请帮我
这是我的代码
' Private Sub UpdateInfo(ByVal USER_ID As Integer)
'Dim User As Integer = USER_ID
'Dim sql1 As String = "UPDATE AdminCoordinatorInformation SET MobileNumber =" + tbmobile.Text + ", HomeNumber=" + tbhome.Text + ", AltRelation = " + DDLRelationShip.SelectedValue + ", AlTitle = " + DDLTitle.SelectedValue + ", AltName = " + tbemname.Text + ", AltMobile = " + tbemmobile.Text + " WHERE USER_ID = User)"
'Dim sql2 As String = "UPDATE DIP_USERS SET USER_Email=" + tbEmail.Text.Trim + " WHERE USER_ID = User)"
' Try
' Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("mydbConnectionString").ConnectionString)
' Dim cmd1 As New SqlCommand(sql1, conn)
' Dim cmd2 As New SqlCommand(sql2, conn)
' cmd2.Parameters.AddWithValue("@FirstName", tbname.Text)
' cmd2.Parameters.AddWithValue("@USER_PASSWORD", tbnewpassword.Text)
' cmd2.Parameters.AddWithValue("@USER_Email", tbEmail.Text)
' cmd1.Parameters.AddWithValue("@MobileNumber", tbmobile.Text)
' cmd1.Parameters.AddWithValue("@HomeNumber", tbhome.Text)
' cmd1.Parameters.AddWithValue("@AltRelation", DDLRelationShip.SelectedValue)
' cmd1.Parameters.AddWithValue("@AlTitle", DDLTitle.SelectedValue)
' cmd1.Parameters.AddWithValue("@AltName", tbemname.Text)
' cmd1.Parameters.AddWithValue("@AltMobile", tbemmobile.Text)
' conn.Open()
'Dim ra As Integer = cmd1.ExecuteNonQuery()
'Dim ra1 As Integer = cmd2.ExecuteNonQuery()
'cmd1.Dispose()
'cmd2.Dispose()
' conn.Close()
' Catch ex As Exception
' MsgBox(ex.Message)
' End Try
'End Sub