|
-
Sep 26th, 2004, 03:32 AM
#1
Thread Starter
Addicted Member
recordcount problem .
Code:
Dim SDaT As String
Dim CTiM As String
SDaT = Format(Date, "dd/mm/yy")
CTiM = Format(Time, "hh:mm")
conn.connectionsettings="AW"
Dim rs As New ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM Attendance where RIC='rnames(fi)' & DateIn='SDaT' ", conn, adOpenStatic, adLockOptimistic, adCmdTable
msgbox rs.RecordCount
i run the above code , but somehow i wasn't able to get any recordcount even though the record exist in the database but the code just by pass the msgbox rs.recordcount and execute the next line ? is any thing wrong with mine rs.open statement ?
-
Sep 26th, 2004, 03:42 AM
#2
In your Open statement you need to replace adOpenStatic with adOpenKeyset or adOpenDynamic
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Sep 26th, 2004, 03:55 AM
#3
Thread Starter
Addicted Member
but i could get -1 froom the record count , anyway parameter still need to be changed ?
-
Sep 26th, 2004, 10:24 AM
#4
The RecordCount property will always be -1 when using a Server Side cursor. Change the CursorLocation property to adUseClient.
Do you use On Error Resume Next? I always thought using a SQL statement and adCmdTable in the rs.Open statement would raise an error. Maybe it depends on the provider.
-
Sep 26th, 2004, 04:00 PM
#5
I cannot even see how that SELECT statement is working - you are not concatenating the two VB variables into the string...
But at any rate you could use a trick...
Code:
SELECT (SELECT COUNT(*) FROM ...),* FROM ...
Here I am adding a SUBQUERY to the start of the SELECT list that is the exact same WHERE clause as the SELECT itself, but does a COUNT(*) - which will be the record count.
Here you get a RECORDCOUNT in each ROW of the total number of rows in the recordset.
Sloppy, ugly, not elegant - but it will work.
-
Sep 26th, 2004, 08:23 PM
#6
Fanatic Member
Originally posted by szlamany
I cannot even see how that SELECT statement is working - you are not concatenating the two VB variables into the string...
But at any rate you could use a trick...
Code:
SELECT (SELECT COUNT(*) FROM ...),* FROM ...
Here I am adding a SUBQUERY to the start of the SELECT list that is the exact same WHERE clause as the SELECT itself, but does a COUNT(*) - which will be the record count.
Here you get a RECORDCOUNT in each ROW of the total number of rows in the recordset.
Sloppy, ugly, not elegant - but it will work.
szlamany is absolutely correct. You use two conditions in your where clause but you forgot to use the AND operator and you call external functions from within the sql string. Try it like this . . .
VB Code:
Dim SDaT As String
Dim CTiM As String
SDaT = Format(Date, "dd/mm/yy")
CTiM = Format(Time, "hh:mm")
conn.connectionsettings = "AW"
Dim rs As New ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM Attendance WHERE RIC='" & rnames(fi) & "' AND DateIn='SDaT'", conn, adOpenStatic, adLockOptimistic, adCmdTable
MsgBox rs.RecordCount
"Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!
Resistance is futile, you will be compiled . . . Please!
-
Sep 26th, 2004, 08:27 PM
#7
Fanatic Member
Sometimes, it's also easier to build the sql string first. Makes the code a little cleaner . . . .
VB Code:
Dim SDaT As String
Dim CTiM As String
Dim strSQL As String
SDaT = Format(Date, "dd/mm/yy")
CTiM = Format(Time, "hh:mm")
conn.connectionsettings = "AW"
Dim rs As New ADODB.Recordset
Set rs = New ADODB.Recordset
strSQL = "SELECT * FROM Attendance WHERE RIC='" & rnames(fi) & "' AND DateIn='SDaT'"
rs.Open strSQL, conn, adOpenStatic, adLockOptimistic, adCmdTable
MsgBox rs.RecordCount
"Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!
Resistance is futile, you will be compiled . . . Please!
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
|