欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp下連接數(shù)據(jù)庫 ASP鏈接數(shù)據(jù)庫字符串大全總結(jié)第2/2頁

 更新時(shí)間:2007年11月22日 22:49:03   作者:  

另外如果是查詢傳入的變量,則如下:

strau=request.form("author")
strsql="select * from book where author='"&strau&"'"

如果查詢的是數(shù)字,則:

intID=request.form("id")
strsql="select * from book where id="&intID

在很多數(shù)據(jù)庫中,如:oracle,上面的語句是可以寫成:
strsql="select * from book where id='"&intID&"'"的。
但是字符型一定不能按照數(shù)字格式寫,需要注意。

2.添加記錄(Insert)
語法:Insert into table(field1,field2,....) Values (value1,value2,....)
例子:添加一作者是"cancer"的記錄入book表:
insert into book (bookno,author,bookname) values ('CF001','cancer','Cancer無組件上傳程序')
同樣,如果用到變量就如下:

strno=request.form("bookno")
strau=request.form("author")
strname=request.form("bookname")
strsql="insert into book (bookno,author,bookname) values ('"&strno&"','"&strau&"','"&strname&"')"

3.用Recordset對(duì)象的Addnew插入數(shù)據(jù)的方法:
語法:

rs.addnew
rs("field1").value=value1
rs("field2").value=value2
...
rs.update

4.修改數(shù)據(jù)記錄(Update)
語法:update table set field1=value1,field2=value2,...where fieldx=valuex
例子:update book set author='babycrazy' where bookno='CF001'
如果用到變量就如下:

strno=request.form("bookno")
strau=request.form("author")
strsql="update book set author='"&strau&"' where bookno='"&strno"'"

5.Recordset對(duì)象的Update方法:
語法:

rs("field1").value=value1
rs("field2").value=value2
...
rs.update

注意:使用語法3和語法5的時(shí)候,一定要注意字段的類型(尤其是日期型)一致,否則出錯(cuò)的幾率非常的高。


例子:

strno=request.form("bookno")
strau=request.form("author")
set adocon=server.createobject("adodb.connection")
adocon.open "Driver={Microsoft Access Driver(*.mdb)};DBQ=" & _
Server.Mappath=("/cancer/cancer.mdb")
strsql="select * from book where bookno='"&strno&"'"
set rs=server.createobject("adodb.recordset")
rs.open strsql,adconn,1,3
if not rs.eof then '如果有此記錄的話
rs("author").value=strau
rs.update
end if
rs.close
set rs=nothing
adocon.close
set adocon=nothing

6.刪除一條記錄(Delete)
語法:Delete table where field=value
例子:刪除book表中作者是cancer的記錄

delete book where author='cancer'

(注意:如果book表中author字段的值為cancer的記錄有多條,將會(huì)刪除所有author為cancer的記錄)

好了,學(xué)會(huì)了用這些操作,大家在用asp操作數(shù)據(jù)庫的時(shí)候,該是沒有什么問題了。

相關(guān)文章

最新評(píng)論