ASP + SQL Summary of various database operations

Source: Internet
Author: User
Relax life Network (relaxlife.net) ASP + SQL personal summary of various database operations

/*************************************** *******************************

*

* 1, --------- ASP + SQL summarize various database operations

*

* If you need moreCode, Please go to: http://www.relaxlife.net feel good to help me top!

*

*

**************************************** *****************************/

<%

'// 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

'// Modification 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) & ", password =" & 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)

'// Deletion 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)



%>

[This post was last edited by cexo255 on]


Author's blog:Http://blog.csdn.net/cexo255/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.