Asp+sql various operations on a database
Last Update:2017-02-28
Source: Internet
Author: User
<%
'//Query method
'//----------------------------(1)-------------------------------
Set rsworkuserinfo = Server.CreateObject ("ADODB. RecordSet ")
strSQL = "Select UserSID, LoginName, UserName, Password"
strSQL = strSQL & "from Users"
strSQL = strSQL & "Where usersid=" & Sqlstr (Tuserid)
If rsworkuserinfo.state = 1 Then
Rsworkuserinfo.close
End If
Rsworkuserinfo.open strsql,conn,1,1
If not rsworkuserinfo.eof Then
LoginName = Rsworkuserinfo ("LoginName")
UserName = Rsworkuserinfo ("UserName")
Password = Rsworkuserinfo ("Password")
End If
Rsworkuserinfo.close
Set Rsworkuserinfo = Nothing
'//----------------------------(2)-------------------------------
strSQL = "Select UserSID, LoginName, UserName, Password"
strSQL = strSQL & "from Users"
strSQL = strSQL & "Where usersid=" & Sqlstr (Tuserid)
Set rsfind = Conn.execute (strSQL)
If not rsfind.eof Then
LoginName = Rsfind ("LoginName")
UserName = Rsfind ("UserName")
Password = Rsfind ("Password")
End If
Rsfind.close
Set Rsfind = Nothing
'//Modify method
'//----------------------------(1)-------------------------------
Set rsworkuserinfo = Server.CreateObject ("ADODB. RecordSet ")
strSQL = "Select UserSID, LoginName, UserName, Password"
strSQL = strSQL & "from Users"
strSQL = strSQL & "Where usersid=" & Sqlstr (Tuserid)
If rsworkuserinfo.state = 1 Then
Rsworkuserinfo.close
End If
Rsworkuserinfo.open strsql,conn,1,3
IF not rsworkuserinfo.eof Then
Rsworkuserinfo ("LoginName") = LoginName
Rsworkuserinfo ("UserName") = UserName
Rsworkuserinfo ("Password") = Md5 (Password)
Rsworkuserinfo.update
Update = True
Else
Update = False
End If
Rsworkuserinfo.close
Set Rsworkuserinfo = Nothing
'//----------------------------(2)-------------------------------
strSQL = "Update Users"
strSQL = strSQL & "Set loginname=" & Sqlstr (LoginName) & ", Username=" & Sqlstr (UserName) & ", Passwo Rd= "& Sqlstr (Password)
strSQL = strSQL & "Where usersid=" & Sqlstr (Tuserid)
Conn.execute (strSQL)
'//Add method
'//----------------------------(1)-------------------------------
Set rsworkuserinfo = Server.CreateObject ("ADODB. RecordSet ")
strSQL = "Select UserSID, LoginName, UserName, Password"
strSQL = strSQL & "from Users"
strSQL = strSQL & "Where usersid=" & Sqlstr (Tuserid)
If rsworkuserinfo.state = 1 Then
Rsworkuserinfo.close
End If
Rsworkuserinfo.open strsql,conn,1,3
If rsworkuserinfo.eof Then
Rsworkuserinfo.addnew
Rsworkuserinfo ("usersid") = Tuserid
Rsworkuserinfo ("LoginName") = LoginName
Rsworkuserinfo ("UserName") = UserName
Rsworkuserinfo ("Password") = Md5 (Password)
Rsworkuserinfo.update
NewRecord = True
Else
NewRecord = False
End If
Rsworkuserinfo.close
Set Rsworkuserinfo = Nothing
'//----------------------------(2)-------------------------------
strSQL = "Insert into Users (UserSID, LoginName, UserName, Password)"
strSQL = strSQL & "Values (" & Sqlstr (Tuserid) & ", & Sqlstr (LoginName) &", "& Sqlstr (UserName) & "," & Sqlstr (Password) & ")"
Conn.execute (strSQL)
'//Delete method
'//----------------------------(1)-------------------------------
Set rsworkuserinfo = Server.CreateObject ("ADODB. RecordSet ")
strSQL = "Delete from Users"
strSQL = strSQL & "Where usersid=" & Sqlstr (Tuserid)
If rsworkuserinfo.state = 1 Then
Rsworkuserinfo.close
End If
Rsworkuserinfo.open strsql,conn,1,3
Rsworkuserinfo.close
Set Rsworkuserinfo = Nothing
'//----------------------------(2)-------------------------------
strSQL = "Delete from Users"
strSQL = strSQL & "Where usersid=" & Sqlstr (Tuserid)
Conn.execute (strSQL)
%>