|
-
Aug 14th, 2001, 12:04 PM
#1
Thread Starter
Addicted Member
ADO rst.recordcount=-1 why?????
what am i doing wrong ????
VB Code:
Set cnn = New ADODB.Connection
strCnn = ADO_PROVIDER & DATA_SOURCE & App.Path & DBNAME
cnn.Open strCnn
Set rst = New ADODB.Recordset
Set cmd.ActiveConnection = cnn
cmd.CommandText = "tblFirstn"
cmd.CommandType = adCmdTable
Set rst = cmd.Execute
Debug.Print rst.RecordCount
-
Aug 14th, 2001, 12:09 PM
#2
PowerPoster
-
Aug 14th, 2001, 12:16 PM
#3
Thread Starter
Addicted Member
not much cuase if u executed the code u can see that when u
then the cursortype changes to adOpenDynamic
and the cursorlocation to adUseServer
how can i change those proprties I m still confused please some more help
thnks
-
Aug 14th, 2001, 01:29 PM
#4
Hyperactive Member
When you use the Connection Object to return a Recordset, it returns a Forward Only, Read Only Recordset. A Forward Only Recordset does not support the RecordCount. If you really need a count you could either open a Recordset Object to get the Recordset, make it not ForwardOnly cursor.
Or you could use the Connection object to return a count then return the recordset. If you are using SQL Server or a Db that can handle mutiple SQL statements in one query then you can combine them in one execute.
VB Code:
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
Dim cn As ADODB.Connection
Set rs = New ADODB.Recordset
Set cmd = New ADODB.Command
Set cn = New ADODB.Connection
Dim SQL String
SQL = "SELECT COUNT(*) FROM T_OBJECT;" & "SELECT * FROM T_OBJECT"
cn.Open "DSN=CRS", "sa"
cmd.CommandText = SQL
cmd.ActiveConnection = cn
cmd.CommandType = adCmdText
Set rs = cmd.Execute(SQL)
' rs(0) will be the record count
Debug.Print rs(0)
Set rs = rs.NextRecordset
' rs will now be the recordset you want
-
Aug 15th, 2001, 05:11 AM
#5
Lively Member
In many cases ,the recordcount can not reflect the actual count unless you perform a MoveLast
Try moving last before quering the recordCount
Palestine will be free again ,and someday all the unjustice will be from the history.
-
Aug 15th, 2001, 09:06 AM
#6
Hyperactive Member
Yes in many cases, mainly DAO recordsets, but not in this case.
-
Aug 17th, 2001, 01:42 AM
#7
Lively Member
I faced the same problem and I changed the cursur type to adOpenStatic. It solved my problem
-
Aug 17th, 2001, 08:15 AM
#8
only "static" / "readonly" will give you a recordcount.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|