Asp+Sql 对数据库的各种操作
时间:2007-09-22 10:38:00
一.ASP使用SQL查询数据库方法:
方法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
二.SQL修改数据库方法
方法一.
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)
三.添加数据库记录方法
方法一.
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)
四.SQL删除数据库记录方法
方法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)
标签:数据库,SQL
0
投稿
猜你喜欢
Python数据分析之 Pandas Dataframe合并和去重操作
2022-12-31 07:11:59
python3写爬取B站视频弹幕功能
2023-10-31 10:00:50
Pandas+Matplotlib 箱式图异常值分析示例
2022-09-19 08:49:39
关于Python中object类特殊方法的解释
2023-08-31 22:19:24
Python分析彩票记录并预测中奖号码过程详解
2023-07-20 04:49:18
Python中列表(List) 的三种遍历(序号和值)方法小结
2022-08-24 23:17:39
Python简单实现区域生长方式
2023-08-08 12:07:38
Python2.6版本中实现字典推导 PEP 274(Dict Comprehensions)
2022-04-13 02:53:50
百万行WPF项目代码重构记录分析
2023-12-30 23:00:28
在任意字符集下正常显示网页的方法二(续)
2023-11-22 17:36:14
jquery实现点击页面计算点击次数
2024-04-16 10:33:17
pytest内置fixture使用临时目录流程详解
2021-12-27 06:49:23
分享6个好用到爆的Pycharm插件
2021-07-07 21:17:59
Python Flask框架模板操作实例分析
2022-09-21 02:56:23
python单例模式的多种实现方法
2023-05-01 12:05:04
python SSH模块登录,远程机执行shell命令实例解析
2022-07-24 21:09:22
asp 自定义分段函数/求第N名成绩
2011-03-25 11:07:00
Go项目编写Makefile规则文件概述
2024-02-06 01:20:07
提高JavaScript执行效率的23个实用技巧
2023-08-15 18:38:12
Pycharm Plugins加载失败问题解决方案
2023-12-28 22:28:49