Visual Basic Database Tutorial - Part 2, Page 3
In order to demonstrate the SQL language, boot up Visual Basic and follow these steps to create our own mini-querying tool:
1. Create a Standard Exe
2. Click Project, Components - in the list that appears, check the item entitled 'Microsoft FlexGrid Control 6.0' (or similar) and click OK. The FlexGrid control allows us to easily display the answers to our database questions
3. Next, add the following controls onto your form so your design roughly matches the below image. Don't worry about naming conventions or whatever at the moment.
- Text Box
- Command Button
- Data control
4. In the Properties window for the FlexGrid control, click on the 'DataSource' property. A list of Data controls will appear - it should just contain the 'Data1' control you added above. Select it.
5. Change the DatabaseName property of the Data control to point to that Nwind.mdb database we talked about last week. Mine is located at "C:\Program Files\Microsoft Visual Studio\VB98\Nwind.mdb"
6. Now insert the following code behind your command button:
On Error GoTo OhDear Data1.RecordSource = Text1.Text Data1.Refresh Exit Sub OhDear: MsgBox "Euston, we have a problem!"
7. Err, that's it!
Brilliant. Now let me briefly explain what we just did.
Page 3 of 8