操纵数据库(查询内容):
On Error Resume Next
tablename = "student"
connstr="Driver={SQL Server};Server=192.168.0.10;UID=test;PWD=test1;Database=wawa"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
set rs=server.createobject("adodb.recordset") '建立recordset对象
sql="select * from "&tablename '构造SQL语句
set rs=conn.execute(sql) '送出SQL
while not rs.eof'一个循环把记录集中的记录全部输出
values=""&rs("sno")&rs("grade")&" "&rs("stu")
response.write values & "
"
rs.movenext'将指针移动到下一条记录
wend'循环结束
rs.close'这几句是用来关闭数据库
conn.close
set rs=nothing
set conn=nothing
%>
操纵数据库(修改内容):
On Error Resume Next
tablename = "student"
connstr="Driver={SQL Server};Server=192.168.0.10;UID=test;PWD=test1;Database=wawa"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
set rs=server.createobject("adodb.recordset")
sql="update " &tablename &" set grade=grade-5"'构造修改SQL语句(update后要有空格)
conn.Execute sql '送出SQL
rs.close'这几句是用来关闭数据库
conn.close
set rs=nothing
set conn=nothing
%>
操纵数据库(删除内容):
On Error Resume Next
tablename = "student"
connstr="Driver={SQL Server};Server=192.168.0.10;UID=test;PWD=test1;Database=wawa"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
set rs=server.createobject("adodb.recordset") '建立recordset对象
sql="delete from "&tablename&" where sno='08'"'构造删除SQL语句
conn.Execute sql '送出SQL
rs.close'这几句是用来关闭数据库
conn.close
set rs=nothing
set conn=nothing
%>
操纵数据库(添加内容):
On Error Resume Next
tablename = "student"
connstr="Driver={SQL Server};Server=192.168.0.10;UID=test;PWD=test1;Database=wawa"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
set rs=server.createobject("adodb.recordset") '建立recordset对象
sql="insert into "&tablename&"(sno,grade,stu) values ('08','86','小刚')" '构造添加SQL语句
conn.Execute sql '送出SQL
rs.close'这几句是用来关闭数据库
conn.close
set rs=nothing
set conn=nothing
%>