Article Options
Recently Viewed
Premium Sponsor
Premium Sponsor

 »  Home  »  .NET Newbie  »  My First Access Database Program. Part 1
 »  Home  »  Data Programming  »  My First Access Database Program. Part 1
 »  Home  »  Data Programming  »  Microsoft Access  »  My First Access Database Program. Part 1
My First Access Database Program. Part 1
by George Poth | Published  01/20/2004 | .NET Newbie Data Programming Microsoft Access | Rating:
George Poth

I have been teaching English in Brazil since 1994 and always wanted to do more for learners than common textbooks can offer. This started with web sites that couldn't reach most students as computers and the Internet are not standard for most people in this country.

Computer tools to help Brazilian students learn a complex language like English are practically non-existent and so I sent some suggestions to software companies. Since Brazil is neither a target market for English textbooks nor for software of this kind, the rejection seemed natural.

As a result, I tried some free developer tools such as Borland's free C++ compiler, Free Pascal, and Envelope's Visual Basic. Envelope's Visual Basic, which is a Microsoft Visual Basic 1.0 clone and still available, suited my taste but I knew it was obsolete technology. In March 2003, I bought a copy of Microsoft Visual Basic .NET Standard and have been hopelessly contaminated with the programming virus ever since.

I mostly write programs for educational purposes. Having discovered the wonderful world of DirectX recently, I am diving into the most entertaining part of programming: games. One can connect teaching with pure entertainment, learning, and culture.

 

View all articles by George Poth...
My First Access Database Program. Part 1

Article source code: my1st_accessdb.zip

Introduction

No, no, this isn't going to be some "Use-the-Data-Form-Wizard" nonsense. Neither is this going to be a real-world program. But before you grumble, curse, and look elsewhere, you should know that the code here will help you to write that real-world program you're probably after. Of course, you will have to make the necessary changes, and that's why I start with something very general and simple.

I don't want to bother you with things such as writing the Access database or starting your design totally from scratch. It's not that I'm lazy; it's more in consideration of those who have such an awfully slow dial-up connection. Such a connection can be a spoilsport when it takes ages to load the page. Since this tutorial is going to be a bit - but just a bit - large, I'm happy when I can cut down on things. Believe me, you'll be happy about that, too - unless you have one of those speedy connections.

Before you start

Before you get going, download the Starter Solution. This Starter Solution doesn't come with a single line of relevant code, but it does come with the Access database, including some made-up entries, a ready-to-use interface, and all icons used in the toolbar. Before you continue, keep an unchanged copy of this downloaded folder in case things go terribly wrong.

Unzip the folder and then open any folders until you see the Database Sample Program solution file. Depending on your operating system, you either have to look for the file extension .sln or for the "Visual Studio Solution" file. Double click this file to open the solution. In the Solution Explorer, double click the frmSample.vb and you should see the form as shown in Figure 01.

(Figure 01)

Study the form, controls, and the properties. If you really don't care about what I've done so far, study at least the toolbar. Click the toolbar once and find the property Buttons in the Properties window. Click where it reads "Collections". Look for the property "Tag". You will see that I have typed keywords there. You should be familiar with those tags by the time we start coding the toolbar.

Connecting to the database

Open the "Data" tab in the toolbox and double click "OleDbDataAdapter" as Figure 02 indicates.

(Figure 02)

This will bring up the "Data Adapter Configuration Wizard" as shown in Figure 03.

(Figure 03)

When you click "Next", you will be asked to "Choose Your Data Connection" as you can see in Figure 04.

(Figure 04)

I assume that this is the first time you are using the connection wizard, so the combo box should be empty. Click "New Connection ..." to get to the properties window shown in Figure 05.

(Figure 05)

By default, people at Microsoft assume you're rich and have SQL, even if you're using the standard edition. So you will see the window asking you to connect to an SQL server. Since I didn't have the necessary change to buy SQL, neither the necessary patience for MSDE, I'll try to make do with Access. So click the Provider tab.

As you can see in Figure 06, the Microsoft guys insist on you having more cash in the bank as I do. Since my name isn't William or Bill for short, I'll insist on using an Access data connection.

(Figure 06)

Click "Microsoft Jet 4.0 OLE DB Provider" as suggested in Figure 07 and then "Next" or simply double click this item.

(Figure 07)

In the connection tab, shown in Figure 08, click the ellipsis and browse to the Access database in the bin folder of the Starter Solution.

(Figure 08)

Double click the "dbSample.mdb". As you can see in Figure 09, the connection path will appear in the text box. Click the "Test connection" button. A message box should tell you that the connection is okay. If this isn't the case, you will have to start all over and see where you have gone wrong.

(Figure 09)

Let's assume that everything went just fine. Click the "OK" button. This will bring you to the window shown in Figure 10. Yes, it's the same window you saw in Figure 04, but this time, the connection path is displayed. It's probably a good idea to write the connection path down; it will help you later to understand why we have to change the connection string (path) inside the code.

(Figure 10)

In Figure 11, you will be asked to "Choose a Query Type". Depending on the software you have installed on your machine, you might have more than one option. Important is that the "Use SQL statements" radio button is selected. If this is so, click "Next" to continue.

(Figure 11)

This will bring you to the "Generate the SQL statements" window as shown in Figure 12. There are different ways to generate those statements, but we will use the simplest way. Click the "Query Builder ..." button.

(Figure 12)

This will bring up the "Add Table" window on top of the "Query Builder" window. The "Add Table" window should look like the one shown in Figure 13.

(Figure 13)

You should see the "tblContacts" which is the name I gave the table. Click the "Add" button and then "Close". You will now see the "Query Builder" window as shown in Figure 14.

(Figure 14)

Check "*(All Columns)" in the tblContacts window as shown in Figure 15.

(Figure 15)

Click the "OK" button. This will bring you back to the "Generate the SQL statements" window as shown in Figure 16. This time, the statements are added.

(Figure 16)

Click the "Next" button. This will bring you to the "View Wizard Results" window as shown in Figure 17. There should be a blue check mark before each item. If this is not so, then you have gone wrong earlier. The error might persist even if you start everything from scratch. You will have to edit the "Windows Form Designer generated code" to correct such an error. If you don't have the courage to do that, delete the entire project and unzip the backup copy you - hopefully - have.

(Figure 17)

If everything went just fine, click the "Finish" button. It might take some moments before you can continue, so be patient. Your component tray, just below your form, should look as shown in Figure 18.

(Figure 18)

Click the "OleDbDataAdapter1" once and go to the Properties window. Change the name, OleDbDataAdapter1, to "odaContacts". The prefix "oda" stands for "OleDbDataAdapter" followed by the name of the table. Change the name of the "OleDbConnection1" to "odcContacts", too. As you certainly guessed, the prefix "odc" stands for "OleDbConnection". Your component tray should now look as shown in Figure 19.

(Figure 19)

Right click the "odaContacts" and choose "Generate Dataset" from the context menu. This will bring up the "Generate Dataset" window as shown in Figure 20.

(Figure 20)

Change "DataSet1" to "pdsContacts". The prefix "pds" stands for "Persistent Data Set". Just make sure the "New" radio button is selected and that the checkboxes for the "tblContacts" and "Add this dataset to the designer" are checked. Figure 21 shows you what this should look like.

(Figure 21)

When this is so, click the "OK" button to continue. Your component tray should now look like the one shown in Figure 22.

(Figure 22)

Click the "PdsContacts1" once to select it if it isn't already selected and change the name in the Properties window to "dsContacts". The prefix "ds" stands for "Data Set". When you're finished, your component tray should look as shown in Figure 23.

(Figure 23)

I think I didn't overstate it when I said that this one's going to be a bit large, did I? Hmm, fact is that we haven't even started yet.

Continued in My First Access Database Program. Part 2

How would you rate the quality of this article?
1 2 3 4 5
Poor Excellent
Tell us why you rated this way (optional):

Article Rating
The average rating is: No-one else has rated this article yet.

Article rating:4.23636363636365 out of 5
 55 people have rated this page
Article Score36935
Related Articles
Comments    Submit Comment

Comment #1  (Posted by an unknown user on 02/13/2004)


 
Comment #2  (Posted by an unknown user on 11/01/2004)

This is a great article. I know absolutely nothing about VB, SQL, databases or programming at all. But I could work through this no problems. thanks.
RP
 
Comment #3  (Posted by an unknown user on 01/11/2005)
Rating
Very simple, easy to understand
 
Comment #4  (Posted by an unknown user on 01/24/2005)
Rating
excellent work for beginners thanks moh

 
Comment #5  (Posted by an unknown user on 01/26/2005)
Rating
At first look,this demonstrates the basic knowledge of .net framework
 
Comment #6  (Posted by an unknown user on 02/05/2005)
Rating
Very easy to follow
 
Comment #7  (Posted by an unknown user on 02/11/2005)
Rating
Well, by far the best way to teach, THANKSSSSSSSSS lot, that's an excellent approach, i am sure the best way not only to teach VB but also some patience{ no sarcasim, i truly :)}
 
Comment #8  (Posted by an unknown user on 02/20/2005)
Rating
That is very good for ppl that don't know VB.net at all.. thanks
 
Comment #9  (Posted by an unknown user on 03/11/2005)
Rating
Thanks, greatly helped me
 
Comment #10  (Posted by an unknown user on 03/27/2005)
Rating
Cuz its so basic :)
 
Comment #11  (Posted by an unknown user on 04/11/2005)
Rating
I find all the George Poth articles to be extremely helpful. Way to go George!!!
 
Comment #12  (Posted by lwami on 04/18/2005)
Rating
this information is very helpful
 
Comment #13  (Posted by an unknown user on 04/18/2005)
Rating
I've already figured this stuff out, from books, forum trawls etc. But I wish I had found this before, it would have saved me a lot of time!
 
Comment #14  (Posted by an unknown user on 04/23/2005)
Rating
very well explained. Many thanks,

Simon
 
Comment #15  (Posted by an unknown user on 05/03/2005)
Rating
u explain it very clear. i am new in vb.net, so manything i get confius when study by myself. i also poor in programing. so, ur expalination step by step and show the screenshot, it make me easy to understand, thanks =)
 
Comment #16  (Posted by an unknown user on 05/18/2005)
Rating
Actually covers everything you need to know to sucessfully follow all the steps.
 
Comment #17  (Posted by an unknown user on 06/21/2005)
Rating
Excellent Tutorial. Both 1 and 2. Fills in the blanks quite painlessly. Those Dallas drivers must be telling him he's number 1.
 
Comment #18  (Posted by an unknown user on 06/22/2005)
Rating
Really cool and I learn a lot from it. if could you give me your yahoo ID so i can add you in my buddy list. thanks =)
 
Comment #19  (Posted by Brian on 06/22/2005)
Rating
Really cool and I learn a lot from it. if could you give me your yahoo ID so i can add you in my buddy list. thanks =)
 
Comment #20  (Posted by an unknown user on 06/22/2005)
Rating
?????! ??????? ????. ???????!
(Cool! It is good idea. Thanks!)
 
Comment #21  (Posted by an unknown user on 07/12/2005)
Rating
Very clear to understand, although, screenshots are in spanish
 
Comment #22  (Posted by an unknown user on 07/14/2005)
Rating
Great thnx, everything is clear now!
 
Comment #23  (Posted by an unknown user on 07/26/2005)
Rating
The first time I've seen a vb.net connection to access explained in plain language. Microsoft should snap you up
 
Comment #24  (Posted by an unknown user on 07/30/2005)
Rating
I like very much the way you teach us. thank you for that
 
Comment #25  (Posted by Hazel on 09/18/2005)

great i find this guide helpful.... lot'cha thanks!
 
Comment #26  (Posted by Hazel on 09/18/2005)

great i find this guide helpful.... lot'cha thanks!
 
Comment #27  (Posted by an unknown user on 12/07/2005)
Rating
excelent
 
Comment #28  (Posted by an unknown user on 12/14/2005)
Rating
It really satisfied me. i was looking for this stuff everywhere. Thanks a lot. My email id is vishi.it@gmail.com. I wouldlike to discuss a lot more with you
 
Comment #29  (Posted by an unknown user on 12/21/2005)
Rating
Excellent Tutorial
 
Comment #30  (Posted by joe serrone on 01/04/2006)
Rating
I appreciate all your hard work on this
 
Comment #31  (Posted by an unknown user on 01/18/2006)
Rating
Easy to follow and extremely accurate, except for all the spanish!
 
Comment #32  (Posted by Meghna on 03/27/2006)
Rating
It is a very good guide for begginners but I keep getting an error that says 'Oledbdataadapter1 has not been configured properly'. Could you help me with this ?
 
Comment #33  (Posted by an unknown user on 04/09/2006)
Rating
i have down loaded this program as directed.But this is not working.kindly advise me what i should do.
 
Comment #34  (Posted by an unknown user on 05/10/2006)
Rating
The Article is very clear and direct.
 
Comment #35  (Posted by an unknown user on 10/31/2006)
Rating
Excellent explanation. This guy explains it like a teacher versus a person who just wants to make things complicated
 
Comment #36  (Posted by an unknown user on 12/21/2006)
Rating
Very Helpful
 
Comment #37  (Posted by an unknown user on 03/06/2007)
Rating
Excellent, up to now
 
Comment #38  (Posted by an unknown user on 03/19/2007)
Rating
You talk of "Use-the-Data-Form-Wizard" nonsense then you use wizards.

Would it not have been better to actually code this rather than using wizards?
 
Comment #39  (Posted by an unknown user on 03/27/2007)
Rating
This has been a learning tool for me that has helped my understanding of how to connect VB.net form controls to Ms access and other types of Databse. I have soley learned from the first time through these articles. Howerver, i still look to see if Mr. GEORGE POTH or any one can help me on how to save an image from Picture box control into Ms Access database or any database (field table of OLE object). Please reach me via Email "Contactbenb@yahoo.com"
 
Comment #40  (Posted by an unknown user on 07/16/2007)
Rating
Thank you very much for your Tutorial. From many days i search like this kind of tutorial. But at last find form this site. Again thank you very much. And try to help all the beginners by this kind of tutorial. From Bangladesh.
 
Comment #41  (Posted by an unknown user on 08/07/2007)
Rating
Step by Step Method is Very Understandable.
 
Comment #42  (Posted by an unknown user on 10/04/2007)
Rating
very very excellent..this will help us to know about linking.thank you!!!
 
Comment #43  (Posted by an unknown user on 12/07/2007)
Rating
To many designers, need to show the code method. Also, did not explain the concept of all the buttons you were clicking, like "what is a data adapter anyway"
 
Comment #44  (Posted by Percival on 06/23/2008)
Rating
seemingly theres a problem with your solution, because every time it will be ported in another host the connection will be lost not just that. I guess it would be better if you could show it in another way or more on a cryptic view by not using the GUI or drag drop fundamentals. The essence of programming was lost. Anyway good for the K1 dude.
 
Comment #45  (Posted by Percival on 06/23/2008)
Rating
seemingly theres a problem with your solution, because every time it will be ported in another host the connection will be lost not just that. I guess it would be better if you could show it in another way or more on a cryptic view by not using the GUI or drag drop fundamentals. The essence of programming was lost. Anyway good for the K1 dude.
 
Comment #46  (Posted by an unknown user on 08/09/2008)
Rating
The graphics and step by step instructions were easy to follow and understand. I did not download the file mentioned by the author as I have VB6 and Access2000. It seems to me that I don't have the appropriate version of VB that is being discussed.
 
Sponsored Links