• Asp+Sql 个人总结对数据库的各种操作


    放松生活网(Relaxlife.net)Asp+Sql 个人总结对数据库的各种操作

    /**********************************************************************
    *
    *        1,---------Asp+Sql 个人总结对数据库的各种操作
    *
    *        如果需要更多代码,请到:http://www.relaxlife.net 感觉好帮我顶!
    *
    *         
    *********************************************************************/

    <%

    '//查询方法
    '//----------------------------(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

    '//修改方法       
    '//----------------------------(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) & ", Password=" & SqlStr(Password)
            StrSql = StrSql & " Where UsersId=" & SqlStr(tUserID)
            Conn.Execute(StrSql)



    '//添加方法
    '//----------------------------(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)


    '//删除方法
    '//----------------------------(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)
           
    %>

    [ 本帖由 cexo255 最后编辑于 2005-4-9 08:25 ]



  • 相关阅读:
    POJ3613 Cow Relays 经过n条边的最短路
    UML笔记(六)
    UML主要内容及参考资料
    UML笔记(五)
    UML笔记(一)
    UML笔记(三)
    UML笔记(四)
    软件工程——第十一章 软件项目管理
    软件工程——第十章 软件工程管理
    UML笔记(二)
  • 原文地址:https://www.cnblogs.com/oop/p/152249.html
Copyright © 2020-2023  润新知