6、Recordset對(duì)象操作數(shù)據(jù)庫(kù)語(yǔ)法
取出news表中前6條數(shù)據(jù)放到rs中
Set Rs=Server.CreateObject("ADODB.RecordSet")
SqlStr="select top 6 * from news"
Rs.Open SqlStr,conn,1,1
3、循環(huán)語(yǔ)句:循環(huán)顯示6條數(shù)據(jù)庫(kù)中的記錄
寫法二:
do while not rs.eof
response.write rs("title")&"< br>"
rs.movenext
loop
5、Access數(shù)據(jù)庫(kù)連接代碼
方法二:
'如果你的服務(wù)器采用較老版本Access驅(qū)動(dòng),請(qǐng)用下面連接方法
db="mydata.mdb" ‘如果放在目錄中,就要寫明"database/mydata.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
connstr="driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath(db)
conn.Open connstr
(3)向數(shù)據(jù)庫(kù)添加一條數(shù)據(jù)代碼
Set Rs=Server.CreateObject("ADODB.RecordSet")
SqlStr="select * from news"
Rs.Open SqlStr,conn,1,3 ‘注意這里的1,3代表可以寫入的打開(kāi)數(shù)據(jù)表
Rs.addnew
Rs("title")=trim(request("title"))
Rs("neirong")=request("neirong")
Rs("date")=now()
rs.update ‘真正寫入數(shù)據(jù)庫(kù)
(4)修改一條記錄的代碼,通過(guò)(2)中的連接傳遞過(guò)來(lái)了id數(shù)值
Set Rs=Server.CreateObject("ADODB.RecordSet")
SqlStr="select * from news where id="&request("id")
Rs.Open SqlStr,conn,1,3 ‘注意這里的1,3代表可以寫入的打開(kāi)數(shù)據(jù)表
Rs("title")=trim(request("title"))
Rs("neirong")=request("neirong")
Rs("date")=now()
rs.update ‘真正寫入數(shù)據(jù)庫(kù)
(5)刪除數(shù)據(jù)庫(kù)中一條記錄,通過(guò)連接傳遞過(guò)來(lái)了數(shù)據(jù)得id數(shù)值
Set Rs=Server.CreateObject("ADODB.RecordSet")
SqlStr="select * from news where id="&request("id")
Rs.Open SqlStr,conn,1,3 ‘注意這里的1,3代表可以寫入的打開(kāi)數(shù)據(jù)表
rs.delete ‘刪除該條數(shù)據(jù)
7、標(biāo)準(zhǔn)Sql語(yǔ)句寫法
包括取全部記錄
Set Rs=Server.CreateObject("ADODB.RecordSet")
SqlStr="select * from news"
Rs.Open SqlStr,conn,1,1 ‘運(yùn)行sql語(yǔ)句,把數(shù)據(jù)提出到rs對(duì)象中
選取幾條數(shù)據(jù)
Set Rs=Server.CreateObject("ADODB.RecordSet")
SqlStr="select top 6 * from news"
Rs.Open SqlStr,conn,1,1 ‘運(yùn)行sql語(yǔ)句,把6條數(shù)據(jù)提出到rs對(duì)象中
選取一條指定表中id字段數(shù)值的數(shù)據(jù)
Set Rs=Server.CreateObject("ADODB.RecordSet")
SqlStr="select * from news where id="&request("id")
Rs.Open SqlStr,conn,1,1 ‘運(yùn)行sql語(yǔ)句,把6條數(shù)據(jù)提出到rs對(duì)象中
添加一條表單傳過(guò)來(lái)的數(shù)據(jù)替換
Set Rs=Server.CreateObject("ADODB.RecordSet")
SqlStr="insert into news(title,neirong) values(request("title"), request("neirong"))
修改一條指定表中id字段數(shù)值的數(shù)據(jù),用表單傳過(guò)來(lái)的數(shù)據(jù)替換
Set Rs=Server.CreateObject("ADODB.RecordSet")
SqlStr="update news set title=’"&request("title")&"’,neirong=’"&request("內(nèi)容")&"’ where id="&request("id")
Rs.Open SqlStr,conn,1,3 ‘運(yùn)行sql語(yǔ)句,把數(shù)據(jù)提出到rs對(duì)象中
刪除一條指定表中id字段數(shù)值的數(shù)據(jù)
Set Rs=Server.CreateObject("ADODB.RecordSet")
SqlStr="delete from news where id="&request("id")
Rs.Open SqlStr,conn,1,3 ‘運(yùn)行sql語(yǔ)句,把數(shù)據(jù)提出到rs對(duì)象中