我必须在访问数据库中使用表格
用户
- 用户身份
- 用户名
- 用户激活
用户信息
- 用户信息
- 用户实名
- 用户电话
然后我从一些 asp:text 字段获取信息到更新处理程序,我知道如何为一个表执行此操作,但不是为 2 个。
通常我用这个
Dim strSQL As String = ""
strSQL = "" & _
"UPDATE Userinfo " & _
"SET userrealname = @therealname, userphone = @theuserphone " & _
"WHERE userinfoid =" & Session("theeditid") & ""
Using connection As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnStr").ConnectionString)
Using updatecmd As OleDbCommand = New OleDbCommand(strSQL, connection)
updatecmd.CommandType = CommandType.Text
updatecmd.Parameters.AddWithValue("@therealname", OleDbType.VarChar).Value = TextBox1.Text
updatecmd.Parameters.AddWithValue("@theuserphone", OleDbType.VarChar).Value = CKEditor1.Text
Try
updatecmd.Connection.Open()
Dim i As Integer = CInt(updatecmd.ExecuteNonQuery())
If i = 0 Then
Session("editsucces") = "NoMatch" 'no rows were updated because none matched the criteria
End If
Catch ex As Exception
Session("editsucces") = "DBerror" 'Something went wrong, such as the database was unavailable
End Try
End Using
End Using
所以我现在的问题是,如何从用户表中添加字段!?user.userid 与 userinfo.userinfoid 中的数字相同。
编辑…………编辑…………编辑…………编辑…………编辑…………编辑…… ........编辑
所以这段代码没问题,还是你建议我改变一些!?
Dim strSQL As String = ""
strSQL = "" & _
"UPDATE Users INNER JOIN Userinfo ON Users.UserID = Userinfo.UserID " & _
"SET Users.Username = [@uname], Users.Password = [@upass], Users.UserActiv = [@uactiv], Userinfo.UserRealName = [@urname], Userinfo.UserEmail1 = [@umail], Userinfo.UserDOB = [@udob], Userinfo.UserPhone1 = [@uphone1], Userinfo.UserPhone2 = [@uphone2], Userinfo.UserPhone3 = [@uphone3], Userinfo.UserYear = [@uyear], Userinfo.UserSick = [@usick] " & _
"WHERE Users.UserID = [@uid]"
Using connection As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnStr").ConnectionString)
Using updatecmd As OleDbCommand = New OleDbCommand(strSQL, connection)
updatecmd.CommandType = CommandType.Text
updatecmd.Parameters.AddWithValue("@uname", OleDbType.VarChar).Value = userinput1.Text
updatecmd.Parameters.AddWithValue("@upass", OleDbType.VarChar).Value = userinput2.Text
updatecmd.Parameters.AddWithValue("@uactiv", OleDbType.VarChar).Value = "Y"
updatecmd.Parameters.AddWithValue("@urname", OleDbType.VarChar).Value = userinput3.Text
updatecmd.Parameters.AddWithValue("@umail", OleDbType.VarChar).Value = userinput4.Text
updatecmd.Parameters.AddWithValue("@udob", OleDbType.VarChar).Value = userinput5.Text
updatecmd.Parameters.AddWithValue("@uphone1", OleDbType.VarChar).Value = userinput6.Text
updatecmd.Parameters.AddWithValue("@uphone2", OleDbType.VarChar).Value = userinput7.Text
updatecmd.Parameters.AddWithValue("@uphone3", OleDbType.VarChar).Value = userinput8.Text
updatecmd.Parameters.AddWithValue("@uyear", OleDbType.VarChar).Value = userinput9.Text
updatecmd.Parameters.AddWithValue("@usick", OleDbType.VarChar).Value = usertextarea.Text
Try
updatecmd.Connection.Open()
Dim i As Integer = CInt(updatecmd.ExecuteNonQuery())
If i = 0 Then
Session("editsucces") = "NoMatch" 'no rows were updated because none matched the criteria
End If
Catch ex As Exception
Session("editsucces") = "DBerror" 'Something went wrong, such as the database was unavailable
End Try
End Using
End Using
Response.Redirect("default.aspx", False)