Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2004

    Unanswered: making a SQL query through ADO


    If I want to make a SELECT query on a database through ADO, how can I do that? Do I use the ADODB.Recordset or ADODB.Command? Also how can I search through the records returned and only return the value of a certain field from the records? For those of you who know PHP and MySQL, what will be the vb equivalent of the following code using a Microsoft Access database:

    $result=mysql_query("SELECT * FROM mytable WHERE myfield='data'");
    do {
    while ($rows=mysql_fetch_array($result));
    return $data;
    For those of you who don't know PHP, the above code is making a SQL query and selecting all the fields of a table called 'mytable' where the value of a field called 'myfield' is 'data'. After that it goes through each record returned, and stores the value of the field 'some_field' from that record in an array. At the end of the code it returns the array containing the values of the 'my_field' from each result record.

  2. #2
    Join Date
    Jan 2004
    Aberdeen, Scotland
    What i think your trying to do is get the results returned in a recordset,

    Store your procedure in a ADODB command and return the values into a recordset

    Something like

        'Execute A SQL Command 
        Set cmdCheck = New ADODB.Command
        Set cmdCheck.ActiveConnection = conSQL
        cmdCheck.CommandText = "SELECT * FROM mytable WHERE myfield=" & Chr(34) & "data" & Chr(34) & ";"
        'Execute the SQL Command and store in a recordset
        Set rstCheck = New ADODB.Recordset
        Set rstCheck = cmdCheck.Execute
    conSQL is the Connection that has already been set up
    You can then work with the recordset to do what you want,
    Look into things such as find and move to traverse your recordset,


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts