急等高手!!ASP查询数据记录问题????
Set conn = Server.CreateObject( "ADODB.Connection ")
DBPath = Server.MapPath( "/data/main.mdb ")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq= " & DBPath
sql= "select * from books where book_name like '% " & bname & "% ' " & "AND book_sort= ' " & bsort & " ' "
Set rs=Server.CreateObject( "ADODB.Recordset ")
Set rs=conn.execute(sql)
执行过查询之后,我怎么样才能获得记录的条数?我用的是ACCESS数据库。用的是VBSCRipt。
------解决方案--------------------你寫的存在如下問題:
Set conn = Server.CreateObject( "ADODB.Connection ")
DBPath = Server.MapPath( "/data/main.mdb ")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq= " & DBPath
sql= "select * from books where book_name like '% " & bname & "% ' " & "AND book_sort= ' " & bsort & " ' "
Set rs=Server.CreateObject( "ADODB.Recordset ") //這句與下面衹要取一個就可以
Set rs=conn.execute(sql) //這句與上面那句衹要取一個就可以
如果采用Execute,剛要查詢兩次
如果采用RecordSet衹要查詢一次
方法如下:
一.采用Execute:
Set conn = Server.CreateObject( "ADODB.Connection ")
DBPath = Server.MapPath( "/data/main.mdb ")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq= " & DBPath
sql= "select * from books where book_name like '% " & bname & "% ' " & "AND book_sort= ' " & bsort & " ' "
sqls = "select count(*) from books where book_name like '% " & bname & "% ' " & "AND book_sort= ' " & bsort & " ' "
set rsc = conn.execute(sqls) //rsc(0)的值,就是RecordCount
set rs = conn.execute(sql)
//這種方法沒測試,不知道行不行,你試一下看看,建議使用RecordSet方法
二.采用RecordSet方法
Set conn = Server.CreateObject( "ADODB.Connection ")
DBPath = Server.MapPath( "/data/main.mdb ")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq= " & DBPath
sql= "select * from books where book_name like '% " & bname & "% ' " & "AND book_sort= ' " & bsort & " ' "
set Rs = Server.CreateObject( "ADODB.RecordSet ")
rs.open conn,sql,1,1
此方法的行記錄爲:
rs.recordcount
------解决方案-------------------- " "Set conn = Server.CreateObject( "ADODB.Connection ")
DBPath = Server.MapPath( "/data/main.mdb ")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq= " & DBPath
sql= "select * from books where book_name like '% " & bname & "% ' " & "AND book_sort= ' " & bsort & " ' "
Set rs=Server.CreateObject( "ADODB.Recordset ")
Set rs=conn.execute(sql) " "中的Set rs=conn.execute(sql)是没有用的,如果用了Set rs=Server.CreateObject( "ADODB.Recordset "),后面就用rs.open sql,conn,1,1
然后再输出rs.recordcount就可以了。如果是要用Set rs=conn.execute(sql),前面的Set rs=Server.CreateObject( "ADODB.Recordset ")是多余的。要取记录数直接用
set rs = conn.execute(= "select count(*) as ss from books where book_name like '% " & bname & "% ' " & &quo