Asp+Sql 对数据库的各种操作
天下维客,你可以修改的网络知识库
<% <BR><BR>'//查询方法 <BR>'//----------------------------(1)------------------------------- <BR>Set RsWorkUserInfo = Server.CreateObject("ADODB.RecordSet") <BR><BR>StrSql = "Select UsersId, LoginName, UserName, Password" <BR>StrSql = StrSql & " From Users" <BR>StrSql = StrSql & " Where UsersId=" & SqlStr(tUserID) <BR><BR>If RsWorkUserInfo.State = 1 Then <BR>RsWorkUserInfo.Close <BR>End If <BR>RsWorkUserInfo.Open StrSql,Conn,1,1 <BR><BR>If Not RsWorkUserInfo.Eof Then <BR>LoginName = RsWorkUserInfo("LoginName") <BR>UserName = RsWorkUserInfo("UserName") <BR>Password = RsWorkUserInfo("Password") <BR>End if <BR><BR>RsWorkUserInfo.Close <BR>Set RsWorkUserInfo = Nothing <BR><BR>'//----------------------------(2)------------------------------- <BR>StrSql = "Select UsersId, LoginName, UserName, Password" <BR>StrSql = StrSql & " From Users" <BR>StrSql = StrSql & " Where UsersId=" & SqlStr(tUserID) <BR>Set RsFind = Conn.Execute(StrSql) <BR><BR>If Not RsFind.Eof Then <BR>LoginName = RsFind("LoginName") <BR>UserName = RsFind("UserName") <BR>Password = RsFind("Password") <BR>End if <BR><BR>RsFind.Close <BR>Set RsFind = Nothing <BR><BR>'//修改方法 <BR>'//----------------------------(1)------------------------------- <BR>Set RsWorkUserInfo = Server.CreateObject("ADODB.RecordSet") <BR><BR>StrSql = "Select UsersId, LoginName, UserName, Password" <BR>StrSql = StrSql & " From Users" <BR>StrSql = StrSql & " Where UsersId=" & SqlStr(tUserID) <BR><BR>If RsWorkUserInfo.State = 1 Then <BR>RsWorkUserInfo.Close <BR>End If <BR>RsWorkUserInfo.Open StrSql,Conn,1,3 <BR><BR>IF Not RsWorkUserInfo.Eof Then <BR>RsWorkUserInfo("LoginName") = LoginName <BR>RsWorkUserInfo("UserName") = UserName <BR>RsWorkUserInfo("Password") = Md5(Password) <BR>RsWorkUserInfo.Update <BR>Update = True <BR>Else <BR>Update = False <BR>End if <BR><BR>RsWorkUserInfo.Close <BR>Set RsWorkUserInfo = Nothing <BR><BR>'//----------------------------(2)------------------------------- <BR>StrSql = "Update Users" <BR>StrSql = StrSql & " Set LoginName=" & SqlStr(LoginName) & ", UserName=" & SqlStr(UserName) & ", Password=" & SqlStr(Password) <BR>StrSql = StrSql & " Where UsersId=" & SqlStr(tUserID) <BR>Conn.Execute(StrSql) <BR><BR><BR><BR>'//添加方法 <BR>'//----------------------------(1)------------------------------- <BR>Set RsWorkUserInfo = Server.CreateObject("ADODB.RecordSet") <BR><BR>StrSql = "Select UsersId, LoginName, UserName, Password" <BR>StrSql = StrSql & " From Users" <BR>StrSql = StrSql & " Where UsersId=" & SqlStr(tUserID) <BR><BR>If RsWorkUserInfo.State = 1 Then <BR>RsWorkUserInfo.Close <BR>End If <BR>RsWorkUserInfo.Open StrSql,Conn,1,3 <BR><BR>If RsWorkUserInfo.Eof Then <BR>RsWorkUserInfo.AddNew <BR>RsWorkUserInfo("UsersID") = tUserId <BR>RsWorkUserInfo("LoginName") = LoginName <BR>RsWorkUserInfo("UserName") = UserName <BR>RsWorkUserInfo("Password") = Md5(Password) <BR>RsWorkUserInfo.Update <BR>NewRecord = True <BR>Else <BR>NewRecord = False <BR>End if <BR><BR>RsWorkUserInfo.Close <BR>Set RsWorkUserInfo = Nothing <BR><BR>'//----------------------------(2)------------------------------- <BR>StrSql = "Insert Into Users(UsersId, LoginName, UserName, Password)" <BR>StrSql = StrSql & " Values(" & SqlStr(tUserID) & "," & SqlStr(LoginName) & "," & SqlStr(UserName) & "," & SqlStr(Password) & ")" <BR>Conn.Execute(StrSql) <BR><BR><BR>'//删除方法 <BR>'//----------------------------(1)------------------------------- <BR>Set RsWorkUserInfo = Server.CreateObject("ADODB.RecordSet") <BR><BR>StrSql = "Delete From Users" <BR>StrSql = StrSql & " Where UsersId=" & SqlStr(tUserID) <BR><BR>If RsWorkUserInfo.State = 1 Then <BR>RsWorkUserInfo.Close <BR>End If <BR>RsWorkUserInfo.Open StrSql,Conn,1,3 <BR><BR>RsWorkUserInfo.Close <BR>Set RsWorkUserInfo = Nothing <BR><BR>'//----------------------------(2)------------------------------- <BR>StrSql = "Delete From Users" <BR>StrSql = StrSql & " Where UsersId=" & SqlStr(tUserID) <BR>Conn.Execute(StrSql) <BR><BR>%><BR>
[编辑]


