Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Creating A Table With The Visual Data Manager

To add a table named “students” to the db.mdb database we created in the previous topic, right-click the Properties item in the Visual Data Manager’s Database window and select the New Table item, opening the Table Structure window you see in Figure 24.4.


Figure 24.4  The Visual Data Manager’s Table Structure window.

Give this new table the name “students” by typing that into the Table Name field, as shown in Figure 24.4. That’s it—it was as quick as that to create a new table.

Now that we’ve created a new table, we’ll add the new fields in this table (Name and Grade) in the next topic.

Creating A Field With The Visual Data Manager

To add fields to the database table named “students” we created in the previous topic, click the Add Field button in the Visual Data Manager’s Table Structure window, opening the Add Field dialog box you see in Figure 24.5.


Figure 24.5  The Visual Data Manager’s Add Field dialog box.

Give this new field the name “Name” by typing that into the box labeled Name and clicking on the OK button. The Add Field dialog box stays open, and the new field is added to the students table. Add another field named “Grade” in the same way. Click on OK to add the field, then click Close to close the Add Field dialog box.

Now in the Table Structure window, click the Build The Table item to build the new table with our two new fields. This creates the students table with two fields: Name and Grade, and opens that table in the Visual Data Manager’s Database window, as you can see in Figure 24.6.


Figure 24.6  Our newly created database.

In the next topic, we’ll enter data into our new table.

Entering Data In A Database With The Visual Data Manager

To enter data into a table in the Visual Data Manager, right-click the table’s entry in the Visual Data manager’s Database window and select the Open item in the menu that opens. In our case, doing so opens the Table: students dialog box you see in Figure 24.7. We’ll use this dialog box to enter the data in our database’s records. We’ll use the data you saw in Figure 24.1, but you can also use it to edit that data.


Figure 24.7  Editing a record in a database.

Using the data in Figure 24.1, enter the name “Ann” and the grade “C” for the first student in the labeled boxes in the Table: students dialog box, as shown in Figure 24.7. Then click Update to add that new record to the database; when the Visual Data manager displays a message box asking if you want to add the new record to the database, click Yes.

To add a new record, click the Add button and add the name “Mark” and the grade “B”, and click Update. Click Yes when the Visual Data Manager asks you if you want to add the new record to the database.

When you’re done entering your records, click the Close button in the Table: students dialog box and close the database with the Close item in the Visual Data manager’s File menu.

Congratulations—you’ve created a new database.

Adding A Data Control To A Program

The Testing Department is calling again. Now that you’ve created a new database file, how about using it in a program? Okay, you say, I’ll look into it.

The database we’ve created in the previous few topics is in Microsoft Access (Jet) format, which is a format you can use with all three data access object sets: DAO, RDO, and ADO. We’ll see how to use the simplest method first: connecting that database to a data control in a Visual Basic program and using that data control with data-bound controls.

The data control is the only intrinsic database control—it’s already in the toolbox. This control’s tool appears as the tenth tool down on the right in the toolbox in Figure 24.8. Double-click that tool now to add a data control to your form.


Figure 24.8  The Data Control tool.

Stretch the data control as you want it. When you stretch the control beyond its original size, you’ll see a space for text in the center of the control; set the control’s Caption property to the name of the database table we’ll be working with—students.

That’s all it takes to add a data control to your program. In the next topic, we’ll see how to connect the data control to a database.

Opening A Database With The Data Control

To connect a data control to a database, you just set the data control’s DatabaseName property to the path and name of the Access/Jet database file you want to open. Here, we’ll use the db.mdb file we’ve created at the beginning of this chapter. In addition, you select the table you want to work with in that file with the data control’s RecordSource property. After connecting the control to the db.mdb database, select the students table in the drop-down list box for the RecordSource property in the Properties window.

You’ve connected the data control to a table in a database. But how do you actually see or modify the data in the database? You do that with bound controls, and we’ll get an introduction to that in the next topic.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.