Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Server Data Access With ADO
Message
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00161540
Message ID:
00161956
Views:
27
>Thanks for the reply. I removed it, but I'm still not getting workable behavior. As I understand it, regardless of how the properties for the recordset are set at the time the Open() method is fired, the provider will set the properties based on its abilities and whether it has been asked for a server side or client side cursor.

I copied your code, changed the DSN to one of mine, and the table name to one of mine and it worked fine. Here's what I did to test your code. I commented our your field name and type loop (which worked fine) and instead output the contents of the table. The table I used is called test and has two fields, testkey and testvalue. The rows look like this:
testkey     testvalue
-------     ---------
1           One
2           Two
3           Three
Test is a free table and the DSN is set for a free table directory. I did test this with a container I have and that worked as well.

Here's the altered code:

***************************************
public oConnect, oRecSet

*/ Create and open the connection
oConnect = CreateObject("adodb.connection")
oConnect.Open("VFPTest")

cSQL = "Select * From test"

*/ Create and open the recordset
oRecSet = CreateObject("adodb.recordset")
oRecSet.CursorLocation = 3
*/oRecSet.Open(cSQL,oConnect,3,3) (Generates OLE Dispatch Error)
oRecSet = oConnect.Execute(cSQL) && Generates a recordset with no records

*!* For nIncr = 0 To oRecSet.Fields.Count - 1
*!* ? Padr("Field Name = " + oRecSet.Fields(nIncr).Name,35) ;
*!* + " | Field Type = " + Alltrim(Str(oRecSet.Fields(nIncr).Type) ;
*!* + " | Value = " + Alltrim(oRecSet.Fields(nIncr).Value))
*!* EndFor
?
? "Record Count = " + Alltrim(Str(oRecSet.RecordCount))

oRecSet.MoveFirst

Do While Not oRecSet.EOF
? oRecSet.Fields("testkey").Value + oRecSet.Fields("testvalue").Value
oRecSet.MoveNext
Enddo
***************************************

Now, the RecordCount property is -1 because the CursorType property is set to 0 which is Open Forward Only. This CursorType doesn't support the RecordCount property because ADO doesn't fetch the records until you tell it to using MoveNext. The odd thing is that it wouldn't let me set the CursorType to Static (3) which does support the RecordCount property. This must be due to the ODBC driver. In fact, if you'll test the value of the CursorLocation property you'll notice that it's not 3 like you set it, but 0 as well, which isn't a value in the enumeration list! Another limitation of the driver I suppose. Maybe John Petersen can weigh in here with a comment on this because it strikes me as rather odd.

Anyway, the code above outputs "Record Count = -1" and then all three rows to the main window just like it should.

So, if you were using the recordcount property to determine whether you had records or not, don't! You probably do have records but just don't know it. One way I've seen people test for records in ADO without relying on the recordcount property is like this:

If Not oRecSet.BOF And Not oRecSet.EOF
* You have records
Else
* You don't have records
Endif

Whew! I hope this windy response helps you!
"It is an important and popular fact that things are not always what they seem. For instance, on the planet Earth, man had always assumed that he was more intelligent than dolphins because he had achieved so much -- the wheel, New York, wars and so on -- whilst all the dolphins had ever done was muck about in the water having a good time. But conversely, the dolphins had always believed that they were far more intelligent than man -- for precisely the same reasons." - Douglas Adams
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform