HelloData: A Simple ADO Application
This simple application steps through each of the four major ADO operations: getting, examining, editing, and updating data. These operations are performed against the Northwind sample database included with Microsoft® SQL Server. To focus on the fundamentals of ADO and to prevent code clutter, error handling in the example is minimal.
To run HelloData
Create a new Standard EXE Visual Basic project that references the ADO library. For more information, see Referencing the ADO Libraries.
Create four command buttons at the top of the form, setting the Name and Caption properties to the values shown in the table at the end of this topic.
Below the buttons, add a Microsoft DataGrid Control (Msdatgrd.ocx). The Msdatgrd.ocx file is included with Visual Basic and is located in your \windows\system32 or \winnt\system32 directory. To add the DataGrid control to your Visual Basic toolbox pane, select Components... from the Project menu. Then check the box next to "Microsoft DataGrid Control 6.0 (SP3) (OLEDB)" and then click OK. To add the control to the project, drag the DataGrid control from the Toolbox to the Visual Basic form.
Create a TextBox on the form below the grid and set its properties as shown in the table. The form should resemble the following figure when you are finished.
Finally, copy the code listed in HelloData Code, and paste it into the code editor window of the form. Press F5 to run the code.
In the following example, and throughout the guide, the user id "MyId" with a password of "123aBc" is used to authenticate against the server. You should substitute these values with valid logon credentials for your server. Also, substitute the "MySQLServer" value with the name of your server.
For a detailed description of the code, see Comments on HelloData.