|
Free
computer Tutorials
|
![]() |
home |
Stay
at Home and Learn
|
||||||
The Database Wizard - Part Two |
|||||||
|
If you have the Visual Basic 2005 Express Edition and NOT Visual Studio, your tutorials are here: Visual Basic 2005 Express database Wizard Tutorial The first part of the tutorial is here: Database project for Visual Studio users
The Visual Studio .NET Database Wizard
In the previous part, we'll left it at a successful connection:
When you click OK to the message, and OK again on the connection Tab, a connection string will appear in the drop down box on the Choose a Data Connection step of the Wizard. Click the Next button to proceed. The next screen of the wizard should look like this:
The Available items box on the left shows you what's been set up in the database itself. This database is a very simple one, and contains just the single table called tblContacts. Select this table, and then add it to the Selected items list by clicking the arrow button:
Once you have selected a table or tables from the database, click the Next button at the bottom. Here's the new screen that appears:
Here is where you choose which items from the database you want on your form. You can choose items from more than one table. You would select a different table by selecting in the "Master or single table" drop down list. The columns in that table would then appear in the columns list. By default, all of the columns are selected. Un-tick the one called ID, and then click the Next button. Here's the final screen:
In the area at the top, How do you want to display your data, select the second item "Single record in individual controls". The tick boxes at the bottom will then be available. Just leave them all selected and then click the Finish button. When you do, a message box will appear.
As this is only a test project, and not something we care about protecting the security of, just click the "Include Password" button. VB.NET will then build a form for you with all the controls on it. Your form should look like this one:
It all looks a bit messy. But that's wizards for you! Notice, though, that your Form1 is left untouched. The wizard has created all this on a separate form.
No more reading these lessons online - get the eBook here!
Go ahead and run the programme. You'll find that your Form1 starts, and not your database form. To remedy this, stop the programme, and from the menu bar click on Project. Select "[ProjectName] Properties" right at the bottom. From the Property Pages dialogue box, change the startup object from Form1 to DataForm1. Click OK, and try running your programme again. Your database form should now run OK. But the textboxes will all be empty. The records from the database are not loaded until you click the Load button at the top. If you go ahead and click the Load button, you might see this error message:
If you do, it may be because your database is Read Only (though ours shouldnt' be). Change the file attributes of the database from an explorer window in XP or 2000. The design of the form leaves a lot to be desired. The Notes textbox is off the screen, and is not Multline; the first name and surname are at the bottom, and the textboxes on the right run off the edge of the screen. Halt your programme and return to the design environment. Rearrange
the controls for a better look:
To scroll through the address book, click the arrow buttons. The double arrows mean "First Record", and "Last Record". The single arrows means "Back one Record" and "Forward one Record." As you can see, there are only 5 entries in the address book. But you don't study a programming course just to be told to use the Wizards! What we'll do next, therefore, is to have a look at just how VB.NET connects to your database, and how it reads the data from it.
Move on to the next part of the VB .NET Database Section --> |