JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Connecting to an MS Jet Database

Visual Basic's data access was originally built to work with the Microsoft Jet data access engine, which is the engine in Microsoft Access. Plenty of people still use Jet databases, often because they use MS Access to create them, so I'll take a look at how to connect a Jet database to your Visual Basic code here. In particular, I'll enter the data you see in the sample table in Figure 20.1, which holds students' names and grades, into an MS Jet database named students.mdb, using MS Access.

Next, as you can see in the Students example on the CD-ROM, I've dragged anOleDbDataAdapter to the main Windows form, as we've also done in the DataAccess example in the In Depth section of this chapter. This opens the Data Adapter Configuration Wizard, as in the DataAccess example. I click the New Connection button in the second window of this wizard to open the Data Link Properties dialog you see in Figure 20.24, where I select the MS Jet data engine in the Provider tab.

Figure 20.24: Using the MS Jet data provider.

Clicking the Next button in the Data Link Properties dialog displays the Connection tab in the same dialog, as you see in Figure 20.25. Here, I navigate to the students.mdb database, and click OK to close this dialog and return to the Data Adapter Configuration Wizard.

Figure 20.25: Accessing an MS Jet database.

In the Data Adapter Configuration Wizard, I select the Name and Grade fields of the Students table, in much the same way as we did in the DataAccess example in the In Depth section of this chapter. Then, also as in that example, I generate a new dataset using the Students table with the Data|Generate Dataset menu item, naming that dataset dsStudents, and connect the new dataset to a data grid. Finally, I fill the data set from the data adapter—like this—when the main form loads:

Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
End Sub

And that's all it takes—you can see the result in Figure 20.26, where this example is displaying the data in the Students table.

Figure 20.26: The Students example at work.
Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor