Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

ADO Recordset


1 reply to this topic

iraldo

iraldo
  • Members
  • 2 posts

Posted 31 March 2004 - 14:26

Hi All,

I'm using the database functions from DatabaseFunctions.rul that I found here. Great tools they work like a charm. Thanks!
But here is mi problem I need to make a small adjustment to make the execution of some commands conditional based on a value from a table on the SQL database.
I've tried using an ADO recordset but its RecordCount is always 0; even when there are records that meet the criteria of my SQL statement.

Is there any other way to extract and access data from an SQL table?

Here are three different approaches that I've used with the same result.
Any help will be greatly appreciated.

//Create the ADO RecordSet
szADOObjID = "ADODB.RecordSet";
set oRecSet = CreateObject(szADOObjID);
oRecSet.ActiveConnection = oConnect;

// Create the ADO Command object to execute the script
szADOCommObjID = "ADODB.Command";
set oCommand = CreateObject(szADOCommObjID);
oCommand.ActiveConnection = oConnect;

szSQL = "SELECT TOP 1 field1 FROM Table1 WHERE 1=1";

// Test 1 using the execute method ADO Command
oCommand.CommandText = szSQL;
oCommand.CommandType = 0x1;
set oRecSet = oCommand.Execute();

// Test 2 using the open method of the RecordSet
oRecSet.Open(szSQL);

// Test 3 using the execute method ADO Connection
set oRecSet = oConnect.Execute("Select * from Sysdata", nRecords, 0x1);

Thanks,

Iraldo.



iraldo

iraldo
  • Members
  • 2 posts

Posted 31 March 2004 - 16:49

Sorry, my mistake.
I forgot to set the RecordSet properties before opening it. I've modified the code as follow and is working OK.

//Create the ADO RecordSet
szADOObjID = "ADODB.RecordSet";
set oRecSet = CreateObject(szADOObjID);
oRecSet.CursorType = 2; // adOpenDynamic
oRecSet.LockType = 3; // adLockOptimistic
oRecSet.CursorLocation = 3; // adUseClient
oRecSet.ActiveConnection = oConnect;

szSQL = "SELECT TOP 1 field1 FROM Table1 WHERE 1=1";
oRecSet.Open(szSQL);