Hi
I have written this code , it is giving me value -1 . Table has no record , it should not give 0 if no record exists.
rscompany.Open "select * from owner", cnn1, adOpenDynamic, adLockOptimistic, adCmdText
I am using SQL Database.
Thanks
Hi
I have written this code , it is giving me value -1 . Table has no record , it should not give 0 if no record exists.
rscompany.Open "select * from owner", cnn1, adOpenDynamic, adLockOptimistic, adCmdText
I am using SQL Database.
Thanks
That line of code doesn't give a value, I presume you are using other code too which does.
Also, "SQL Database" is not descriptive enough... there are hundreds of database systems which use SQL, dozens of which have SQL as part of their name (MySQL, SQL Server, ...), and each of those has multiple versions.
(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)
You don't say where you are seeing the -1. I guessing it is rscompany.RecoredCount. I think getting that to populate with zero depends on your cursor options. Using these I get a recordcount of zero. I freely admit I don't understand how they function together and maybe someone else can chime in.
rsTempRecordset.Open strSQL, cnRate, adOpenStatic, adLockReadOnly
I am assuming that there is a line that follows which check the recordcount of the recordset returned.
Rs.Recordcount will always return -1 unless you are using a Client side cursor as it will not know how many records there are. -1 indicates that there is an unknown number of records could be 0 could be 500 or more
if you had used
when you open your connection then your recordcount would reflect the number of records returnedCode:cnn1.CursorLocation=adUseClient
Interesting.....this line works fine with an empty table in MS ACCESS.
And when I look at rscompany.recordcount. it is ZERO.
So, you are either not using MS ACCESS or you are getting the -1 from some other check than recordCount (or as DM points out, not client side).
There are also a number of posts on this forum why you cannot trust that number (RecordCount). I always have used it and have not had any issues I'm aware of. There are a number of warning on this site though as I mentioned.
@Tyson...aye....always best to add a counter and increment as one runs through the recordset.-That will give a TRUE record count
In my experience using a client side cursor has always returned an accurate recordcount in ADO. DAO requires you to do a movelast before the recordcount can be trusted and a server side cursor makes for faster execution with less network traffic.
In general you should not use the client side cursor and thus not the recordcount property. Most times people are just checking to see if the count is > 0 anyway for which a simple test of the .EOF flag works just as well and when using a server side cursor makes for better performance.