|
Just Iterate through the Records in a Table
by Rick Meyer
|
|
1. Start a new standard exe.
2. In Project->Components add the ADO Control
3. On Form1 put an ADO Data Control.
4. On Form1 put 3 Textboxes.
5. On Form1 put an ImageBox.
      Form1 should look like the picture above.
|
|
|
Installed with Visual Basic is a demo Northwind database. It should be in your VB directory called Nwind.mdb (mdb is the extension used for an Access database). If you have VB 5.0 then it is at C:\Program Files\DevStudio\VB\Nwind.mdb
To connect to a database using an ADO Data Control the connection string must be set in the properties of the control. Click [here] to refer to my transition page to see how to do this. The Provider will be the Microsoft.Jet and the Data Source is nwind.mdb mentioned above.
|
|
Since you have already provided the connection string, a drop down list of the tables in the database should appear when you click on the RecordSource (or Table). Choose Categories.
|
|
Now connect each Textbox to the Data Control.
To do this find the DataSource property of each Textbox. Click on the tab and choose the Data Control from the dropdown list.
|
|
Now we want to identify each Textbox with a field in the Categories table. Since we have already set the RecordSource to the Categories table for Data1, and connected each Textbox to Data1, VB is able to provide a dropdown list of all the fields in the table named Categories.
You will find this dropdown list in the Textbox property called DataField. So click the tab for each Textbox and choose one of the first three fields for each. Set the Multiline property to True for the Textbox you have chosen for Description.
|
|
Note that the ImageBox is not bound because we did not set its DataSource or DataField properties. Strangely, ADO doesn't allow pictures to flow automatically to a picture control like in DAO. To do it we need to the following code. Select all of the following code by clicking on the word 'Option' three times and copy it to the clipboard [Ctrl][Insert]. Then paste it into the code window of Form1 with [Shift][Insert].
|
Option Explicit
Private Sub ISGData1_Reposition()
Dim L&, j&, f%, t$
L = ISGData1.Recordset!Picture.ActualSize
ReDim b(L) As Byte
b = ISGData1.Recordset!Picture.GetChunk(L)
t = "tmp"
f = FreeFile
Open t For Binary Access Write As f
For j = 78 To UBound(b)
Put f, j - 77, b(j)
Next
Close f
Set Image1.Picture = LoadPicture(t)
End Sub
|
|
There are 3 references to ISGData above. Change these to the name of your data control.
|