Asp+Sql 对数据库的各种操作

2016-01-29 17:07 1 1 收藏

Asp+Sql 对数据库的各种操作,Asp+Sql 对数据库的各种操作

【 tulaoshi.com - ASP 】

<%

'//查询方法
'//----------------------------(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) & ")" [next]
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(Str

来源:http://www.tulaoshi.com/n/20160129/1500385.html

延伸阅读
标签: ASP
  目前管理信息系统已从传统的客户机/服务器(C/S)模式转向了浏览器/服务器(B/S)模式,特别是微软公司推出它的新产品ASP语言之后,这种转变更加迅猛。管理信息系统的核心是对数据库进行包括添加、修改和查询等等操作,ASP提供的ADO数据库接口控件,使得程序员再也勿需编写复杂的CGI程序了,而只要用几句简单的语句即可实现以上操作。目...
标签: ASP
  <form method="post" name="myform" action="?action=backupdatabase" 选择操作:<INPUT TYPE="radio" NAME="act" id="act_backup"value="backup"<label for=act_backup备份</label <INPUT TYPE="radio" NAME="act" id="act_restore" value="restore"<label for=act_restore恢复</label <br数据库名:<IN...
标签: ASP
     大家在书写asp程序时,最担心的可能就是数据库的连接信息,会被一些人看到,进行一些破坏。下面我们用vb6.0来做一个动态链接库(.dll)来隐藏数据库的连接信息。 启动vb6.0,新建--Active  dll工程。单击"工程"--引用,选择"microsoft  active  server  pages  object  library" 和"...
标签: ASP
一、asp的对象存取数据库方法 在asp中,用来存取数据库的对象统称ado(active data objects),主要含有三种对象: connection、recordset 、command connection:负责打开或连接数据 recordset:负责存取数据表 command:负责对数据库执行行动查询命令 二、连接各数据库的驱动程序 连接各数据库可以使用驱...
编写的把文件的内容写入到数据库的代码如下 首先 建立 数据库表 id char data image(注意此处不要用text类型 text类型与binary不兼容) 代码如下: import java.io.*; import java.sql.*; public class Db { public static void main(String[] args) { Db ac = new Db(); String blobname = "D:\\test1.txt"; //blob...