Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recordcount always -1 2

Status
Not open for further replies.

Smarty

Programmer
Apr 12, 2001
191
0
0
BE
i have this code:

Set Conn2 = Server.CreateObject("ADODB.Connection")
' conn.close
Conn2.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data source=" & Server.MapPath("..\Data\maillist.mdb")
dim ssql
ssql = "select * from maillist where email = '" & request("uemail") & "';"
set rs = conn2.execute(ssql)
response.write ssql
response.write rs.recordcount
'--------------

The recordcount always gives me "-1" although there is an actual record... what is wrong here??
How can i see correctly when there is a record and when there are none?

Thanx,
Smarty
 
Hi Smarty

Add the code

set rs = server.createobject("adodb.recordset")
rs.CursorLocation = adUseClient

If that doesn't work try adding this code as well:

rs.CursorType = adOpenKeyset
 
this only made it worse or i am doing the wrong things... (the second option is most likely)
THIS CODE:
dim rs
set rs = server.createobject("adodb.recordset")
rs.CursorLocation = adUseClient
rs.CursorType = adOpenKeyset
Set Conn2 = Server.CreateObject("ADODB.Connection")
' conn.close
Conn2.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data source=" & Server.MapPath("..\Data\maillist.mdb")
dim ssql
ssql = "select * from maillist where email = '" & request("uemail") & "';"
set rs = conn2.execute(ssql)

GAVE THE FOLLOWING ERRORS:
at line rs.cursorlocation => wrong type of arguments or conflicts or so


 
Are you including adovbs.inc?

If not try:

rs.CursorLocation = 3
rs.CursorType = 1
 
dun use .execute method for this.

the .execute method is a one way reading of the table and since you cant read backward, methods like recordcount and movelast wont work.

use this instead.

strSQL ="SELECT * FROM someTable"
Set rstMain = Server.CreateObject("ADODB.Recordset")
rstMain.Open strSQL, objConn, 3, 1 '3 - static, 1 - readonly

with this then you can use the recordcount method.
 
I guess i solved it another way by checking if the recordcount = 0 (isn't that equal to empty?)
 
The key to making the recordCount property work is declaring the cursorType of a recordset. It has to support all types of movement (forward & back). Check out faq333-618 for more information on the subject.

:)
Paul Prewett
penny.gif
penny.gif
 
This is what i'm using and works just fine


Const adOpenStatic = 3
Const adUseClient = 3
Const adLockPessimistic = 2

set rs=server.CreateObject("ADODB.Recordset")

sub ExecuteSQL(byval cmd)
if rs.State=1 then rs.Close 'if allready open close before reopen
rs.CursorType = adOpenStatic
rs.CursorLocation = adUseClient
rs.LockType = adLockPessimistic
rs.Source = cmd
rs.ActiveConnection = Connection 'The record set needs to know what connection to use.
rs.Open
end sub


and use
ExecuteSQL "select * from mytable"
and use rs to access the fields... ________

George
 
And Connection is declared like that

Set Connection = Server.CreateObject( "ADODB.Connection" )
Connection.Open "Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;Initial Catalog=Tablename;Data Source=JONNY"
________

George
 
Howdy,

The RecordCount property only guarantees that it will be non-zero for a recordset with values. The database engine attempts to returns the true value in this property in most cases, but can do so only if a unique key value is included in the field list. To guarantee a recordcount check if <> 0 then MoveLast and MoveFirst. It will take time. After that process the RecordCount property will be properly populated. SQL Server is more particular than Access regarding this issue...

Roger
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top