Data Control

Viewing a simple database

I will now take you through the few basic steps required to create a program that will show you records in an Access database. We will then eventually expand this program, to provide support for adding & deleting records, and searching etc.

Firstly, create a new project, and add a DataControl to the form. It looks like this: . Set its name property to datTitles, and its Text property to Titles. 

Next, you can click the ... (3 periods) next to the DatabaseName property. A browse dialog will be shown. An example Access database, which we will use, called Biblio.mdb is provided with VB, and should be located in the same folder that VB was installed in. If you can't find it, you can download it here. Before proceeding, I recommend you save a copy of it and name it Biblio_original.mdb, so that if you make any changes you don't like you can restore the original database without having to reinstall VB, or search around on the CD.

Once you have located the file, select it, and click open. This has specified the database where the control will get its information from.

Now you need to select the table you want the control to get the fields from - click the arrow next to the RecordSource property, and select Titles

These are the basic steps in using the Data Control. Next, you need to add some labels and text boxes that will show the contents of each field. In order to do this, you need to bind them to the Data control, by setting each of the text boxes DataSource property to datTitles (the DataControl), and setting its DataField property to the field you want it to display. You can also add labels next to each text box so that the user knows what field each textbox is linked to. Add the following text boxes:

Name DataSource DataField
txtTitle datTitles Title
txtYearPublished datTitles Year Published
txtISBN datTitles ISBN
txtPubID datTitles PubID
txtDescription datTitles Description

Now, save and run your project. Try clicking each of the arrows on the DataControl. You will see, that the control loops through each record in the table, and updates the text in all of the bound text boxes. All without you writing a single line of code!

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.” - Rick Osborne