-
Apr 28th, 2012, 08:56 AM
#1
Thread Starter
Lively Member
Check if a record with a specific ID exists
I want to check if a record with ID 1 exists.
Code:
rs.Open "SELECT * FROM tblTransaction WHERE TransactionID = 1", DBConn
There are no records with ID 1. rs.Fields.Count returns 9. How can it?
Learning to Program on Earth until I go into Outer Space...
-
Apr 28th, 2012, 10:22 AM
#2
Re: Check if a record with a specific ID exists
rs.Fields.Count will return the number of Columns in the Table.
rs.RecordCount may return the number of rows selected.
-
Apr 29th, 2012, 02:56 AM
#3
Re: Check if a record with a specific ID exists
Thread moved to the 'Database Development' forum (the 'VB6' forum is only meant for questions which don't fit in more specific forums)
In addition to what Doogle said, if you just want to check if any records exist then rs.RecordCount is a bad idea (it is slow, and as implied above may not return the amount), instead you should check rs.EOF (if it is True there are record(s), if it is False there aren't).
-
Apr 30th, 2012, 05:10 PM
#4
Junior Member
Re: Check if a record with a specific ID exists
Checking both .EOF and .BOF is a little more thorough, because there is never a situation in which that can arise except an empty recordset. So:
Code:
With rs
.Open 'blah blah
If .EOF And .BOF Then
'It's empty
Else
'It isn't
End If
End With
Also, .RecordCount isn't always accurate, depending on the CursorType you use.
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
|