I want to check if a record with ID 1 exists.
There are no records with ID 1. rs.Fields.Count returns 9. How can it?Code:rs.Open "SELECT * FROM tblTransaction WHERE TransactionID = 1", DBConn
I want to check if a record with ID 1 exists.
There are no records with ID 1. rs.Fields.Count returns 9. How can it?Code:rs.Open "SELECT * FROM tblTransaction WHERE TransactionID = 1", DBConn
Learning to Program on Earth until I go into Outer Space...
rs.Fields.Count will return the number of Columns in the Table.
rs.RecordCount may return the number of rows selected.
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).
(2007, 2008, 2009, 2010, 2011, 2012) . . . . . . . . Hitchhiker's Guide to Getting Help at VBForums
Classic VB FAQs (updated Oct 2010) ...Database Development FAQs/Tutorials (updated May 2011)
(includes fixing common VB errors) .......... (includes fixing common DB related errors, and [Classic VB] ADO tutorial /further steps, and [VB.Net] ADO.Net Tutorial).
Tutorial: How to automate Excel from VB6 (or VB5/VBA) .. SQL 'Select' statement formatter/checker .. Convert colour number to colour name .. FlexGrid: fill from recordset .. FlexGrid: AutoSize columns .. DB Reserved Words checker
Connection strings .. MDAC/Jet/ACE downloads .. SQL Server downloads .. MZTools (free upgrade for the VB6/VBA Editor)
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:Also, .RecordCount isn't always accurate, depending on the CursorType you use.Code:With rs .Open 'blah blah If .EOF And .BOF Then 'It's empty Else 'It isn't End If End With