1
The rs.recordcount value of mssql--asp is negative 1.
Only when the database is called in ADO mode, there is a recordcount. When using a stored procedure, you need to use select count(*) from table_name to count it yourself.
? This is wrong. Stored procedures can also be opened with ado, for example: rs.open "exec SomeProc", conn, 1, 3. My solution is rs.open sql,conn,1,1 to solve this problem.
2
Usually people use the following two methods to execute SQL statements:
Set Rs=Conn.Execute(SqlStr)
and
Set Rs=Server.CreateObject("ADODB.RecordSet")
Rs.Open SqlStr,Conn,CursorType,LockType
(RecordSet object methods please see here)
Since the default recordset cursor is the server cursor,
Rs.CursorLocation = adUseServer
So return Rs.RecordCount=-1,
The server cursor should be changed to a client cursor.
Rs.CursorLocation = adUseClient
Rs.Open SqlStr,Conn,CursorType,LockType
rs.cursortype
cursor type recordcount attribute
----------------------------------------
ForwardOnly 0 (default) returns -1
Keyset 1 correct number of records
Dynamic 2 -1 or incorrect number of records, depending on data source
Static 3 correct number of records
so Rs.CursorLocation = 3
Recordset.support("property name") can be used to test whether the property is supported.
http://www.dwww.cn/new/20051128112149636.html
3
Set oRs = Server.CreateObject("ADODB.RecordSet")
oRs.Open sSql, oConn, 1, 1
To read data,
otherwise use Select Count(*) As RecordCount From [table]
oRs("RecordCount") to get
or use Do While Not oRs.Eof
RecordCount = RecordCount + 1
Loop
4My database is connected like this:
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("bbs.mdb")
set conn = server.createobject("adodb.connection")
conn.open strconn
sql="SELECT * FROM space "
set rs=createobject("adodb.recordset")
rs.open sql,conn,1,1
but there is indeed a record set returned and it can be displayed