I have to tabels in an access db
User
- userid
- username
- useractiv
Userinfo
- userinfoid
- userrealname
- userphone
i then get the info from some asp:text fields to the update handler, i know how to do this for one table but not for 2.
normally i use this
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
So my question is now, how can i add the fields from the user tabel !?
The user.userid is the same number as in userinfo.userinfoid.
EDIT……..EDIT……..EDIT…….EDIT……….EDIT………EDIT……….EDIT
So this code is ok, or do u recoment that i changes some of it !?
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)
It should be possible to create a join to update both tables. For example: