ActiveX Data Objects

Using ActiveX Data Objects

In this exercise, you will use Visual Basic and ADO to connect to a data source and create a recordset. A partial solution has been provided for you.

* To open the ADO Project

  1. Start Visual Basic 5.0 .
  2. From the New Project dialog, select the Existing tab.
  3. Locate WA\Practice\Ch07\Lab7ado.vbp and click Open .
  4. When prompted to add the project to Visual SourceSafe, click No .
  5. From the Project menu, click References .

    Note that a reference has been made to the Microsoft OLE DB ActiveX Data Objects 1.0 Library .

* To connect to an ODBC data source

  1. In the General Declarations section of frmADO , create the following form-level object variable:
     Dim rs As New ADODB.Recordset 
  2. Open the code window for the cmdConnect_Click event.
  3. Add the following ADO code to open a recordset:
     rs.Open "SELECT LastName, FirstName FROM Employees", _ "DSN=nwind;", adOpenKeyset 
* To fill the textboxes with data from the employees table
  1. From the object list box on the code window choose (General).
  2. From the procedure list box on the code window choose FillTextBoxes .
  3. In this procedure, you will write the code to fill the text boxes as in the example below.
     txtFirstName.Text = rs!firstname txtLastname.Text = rs!lastname 
* To examine the code in the rest of the application
  1. Review the code in the cmdFirst , cmdPrevious , cmdNext and cmdLast click events.
  2. Save your work.
  3. Start and test the application.


Microsoft Windows Architecture Training
Microsoft Windows Architecture for Developers Training Kit
ISBN: B00007FY9D
EAN: N/A
Year: 1998
Pages: 324

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net