一、添加记录
方法1:Connection对象的Execute方法
set con=Server.CreateObject("ADODB.Connection")
insertstr="insert into 表名(字段1,字段2,...) values(value1,value2,...) '插入记录SQL语句
con.Open constr
con.Execute(insertstr)
con.close
set con=nothing
-------------------------------------------------------------------------------------------
方法二:RecordSet对象的AddNew方法
set con=Server.CreateObject("ADODB.Connection")
set rs =Server.CreateObject("ADODB.RecordSet")
querystr="select * from 表名" '查询记录SQL语句
con.open constr
rs.open querystr,con,1,3
rs.AddNew
rs("字段1")=value1
rs("字段2")=value2
......
rs.Update
rs.close
set rs=nothing
con.close
set con=nothing
二、查询记录
set con=Server.CreateObject("ADODB.Connection")
set rs =Server.CreateObject("ADODB.RecordSet")
querystr="select 字段 from 表名 where ...." '查询记录SQL语句
con.open constr
rs.open querystr,con,1,1
do while not rs.EOF do
'读取数据
变量1=rs("字段1")
变量2=rs("字段2")
...
loop
rs.close
set rs=nothing
con.close
set con=nothing
三、修改记录
方法一:Connection对象的Execute方法
set con=Server.CreateObject("ADODB.Connection")
con.open constr
updatestr="update 表名 set 字段1=value1,字段2=value2 where id=..." '更新记录SQL语句
con.Execute(updatestr)
con.close
set con=nothing
----------------------------------------------------------------------
方法二:RecordSet对象的Update方法
set con=Server.CreateObject("ADODB.Connection")
set rs= Server.CreateObject("ADODB.RecordSet")
querystr="select 字段 from 表名 where ...." '查询记录SQL语句
con.open constr
rs.open querystr,con,1,3
rs("字段1")=value1
rs("字段2")=value2
...
rs.Update
rs.close
set rs=nothing
con.close
set con=nothing
四、删除记录
set con=Server.CreateObject("ADODB.Connection")
deletestr="delete from 表名 where id="&id '删除记录SQL语句
con.open constr
con.Execute(deletestr)
con.close
set con=nothing