|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
RecordCount with adOpenStatic = -1
Hi All,
I'm having a hell of a time with this... From researching multiple websites, specifying the asOpenStatic cursor should return the correct RecordCount. Here is my code: sql = "SELECT UserID,UserName,Password,AccessLevelID,LockThreshold,Active FROM tbl_users WHERE UserName = '" & username & "' and Password = '" & password &"' " set rs_login=Server.CreateObject("ADODB.Recordset") rs_login.Open sql, conn, adOpenStatic', adLockReadOnly, adCmdTable if rs_login.RecordCount <> 0 then Response.Write("Login Successful" & "<br>") Response.Write("Record Count: " & rs_login.RecordCount) end if I know I can use the select count(*) instead, but I've been researching this for quite some time now and I would like to know what's wrong. Thx, |
|
#2
|
|||
|
|||
|
Why not use
If YourRecordSet.EOF Then response.Write "Sorry No Records Found" Else 'Output of Records found End If ????????? |
|
#3
|
|||
|
|||
|
Just a simple question, but have you defined the variable adOpenStatic in your asp pages? adOpenStatic isn't defined by default, you have to define it a) yourself or b) include adodb.inc which is available from microsoft which defines all ADODB constants.
Dim lRS: Set lRS = CreateOBject("ADODB.RecordSet") lRS.Open lCmd, , adOpenStatic Response.Write lRS.RecordCount -> w/o definition of adOpenStatic (which is then the same as "") it returns -1 if i do adOpenStatic = 3 and the execute it, it returns the valid RecordCount. |
|
#4
|
|||
|
|||
|
I use the .inc file from MS.
|
|
#5
|
|||
|
|||
|
Code:
<%
Dim lConn
Set lConn = CreateObject("ADODB.Connection")
lConn.ConnectionString = "Provider=SQLOLEDB.1;User ID=username;Password=password;Data Source=hostname;Initial Catalog=database"
lConn.Open
Dim lRS
Set lRS = CreateOBject("ADODB.RecordSet")
lRS.Open "SELECT * FROM TTodo", lConn, 3
Response.Write lRS.RecordCount
%>
Perhaps your provider/driver doesn't support adOpenStatic? Which driver are you using and which database? |
|
#6
|
|||
|
|||
|
cursorLocation
there are some properties, that are not supported on mySQL server; one of such is adUseServer cursorLocation for counting the total of affected rows.
if you use adUseServer cursorLocation, you will get -1 as a number of affected rows, no matter what (even, if you properly open the connection, ie. adOpenStatic) right solution is to use adUseClient cursorLocation. Here is a sample snippet of code: MyConn = ...connectionString... Set Conn = Server.CreateObject("ADODB.Connection") Conn.open MyConn, "", "" Set RS = Server.CreateObject("ADODB.Recordset") pogoj = "SELECT * FROM database" RS.CursorLocation = adUseClient RS.Open pogoj, Conn, adOpenStatic, adLockOptimistic counter = RS.RecordCount hope, this will help Last edited by faithBHP : August 28th, 2003 at 05:05 AM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > RecordCount with adOpenStatic = -1 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|