<%
Dim db,connStr,conn,sql,rs
‘数据库文件名
db = "test.mdb"
‘数据库连接字符串
connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)
‘创建连接connection对象的实例
Set conn = server.createobject("ADODB.Connection")
‘调用conn的open方法打开连接
conn.open connStr
‘sql语句 tb_user为表名
‘修改 sql = "UPDATE tb_user Set username=‘test1‘ where userid=1"
‘删除 sql = "DELETE from tb_user where userid=1"
‘添加 sql = "INSERT INTO tb_user (username,sex) VALUES(‘test1‘,‘女‘) "
sql="select username FROM tb_user where userid=1" ‘查询
‘创建ADODB.RecordSet 数据记录的对象实例 rs
Set rs = server.createobject("ADODB.Recordset")
‘执行sql语句获取记录集
rs.Open sql,conn,1,1
‘判断是否有数据,有则输出,无则提示
if not rs.EOF Then
response.write(rs("username"))
else
response.write("没有该用户")
%>
ps:
set rs = server.createobject("ADODB.recordset")
rs.open sql,conn
可以用替换为
set rs=conn.execute(sql)
效果一样