Article Options
Recently Viewed
Premium Sponsor
Premium Sponsor

 »  Home  »  .NET Newbie  »  ADO.NET for Beginners Part One
 »  Home  »  Data Programming  »  ADO.NET  »  ADO.NET for Beginners Part One
ADO.NET for Beginners Part One
by David Jeavons | Published  07/12/2006 | .NET Newbie ADO.NET | Rating:
David Jeavons
I have been programming database applications for almost 12 years starting out with VB3 and using every major version since then. I currently work for a retailer analysis company writing ASP.NET code for our ever evolving web site. I also enjoy helping other programmers with Visual Basic and .NET and am a moderator at vbCity. 

View all articles by David Jeavons...
The Address Book User Interface

First things first, we will need a database. Attached to this article is an Access database that I prepared earlier and will form the basis for this guide. If you download this database now, we will then move along to creating the user interface.

I have based this tutorial on code that is compatible with the .NET Framework 1.1 so you can use either VS 2003 or 2005 when following along. Assuming that you now have your development environment loaded, the first thing we will do is to create a project. A Windows Application project type is required for this demonstration and the code in this tutorial is written in VB.NET.

As the first part of this tutorial is solely concentrating on how to connect to a database and retrieve simple information, the user interface does not need to be too complex. So the ideal control to drop onto our form at this point will be the DataGrid (Note, if you are using VS 2005 you can add the DataGrid component to your Toolbox by right clicking on the Toolbox and selecting "Choose Items...". Alternatively, use the DataGridView component). I have named my DataGrid "dgContacts" and have also added a button to the bottom of the form in order to close the application, aptly named "btnClose". Your user interface should then resemble something similar to the following screen shot:


The Address Book User Interface

The next part of this tutorial will look at connecting to the database that you downloaded previously and populating the DataGrid with the contents of the "Contacts" table from said database. Before moving on however, I recommend that you copy the database that you have downloaded to your projects bin\Debug folder. This will make connecting to the database easier as we will know that the location of the database will be in the same place as the executable for this program and thus we can use the Application.StartupPath method to grab this location.

Comments    Submit Comment

Comment #1  (Posted by an unknown user on 07/12/2006)
Rating
Very nice. Looking forward to the rest.
 
Comment #2  (Posted by an unknown user on 08/07/2006)
Rating
What if my database has a password an not in a dbw group?
 
Comment #3  (Posted by David Jeavons on 08/08/2006)
Rating
If your database is password protected then you will need to modify your connection string to include the user credentials. The site below contains many examples of connection strings:

http://www.carlprothman.net/Default.aspx?tabid=86#OLEDBManagedProvider
 
Comment #4  (Posted by an unknown user on 08/30/2006)
Rating
Very good introduction.
How do I download the db and the sample code? I could not find any link.
 
Comment #5  (Posted by an unknown user on 08/30/2006)
Rating
Hi

Thank you for your comments.

You can download the database by going to page 4 of this article and at the bottom (just above the comments) you will see the AddressBook.zip attachment.
 
Comment #6  (Posted by an unknown user on 09/07/2006)
Rating
It didnt bloody work, did it
 
Comment #7  (Posted by David Jeavons on 09/07/2006)
Rating
Would you care to elaborate :)
 
Comment #8  (Posted by Jake on 09/08/2006)
Rating
will not compile

error = dgContacts

name dgContacts is not declares
 
Comment #9  (Posted by David Jeavons on 09/09/2006)
Rating
Hi Jake

When you placed the DataGrid or DataGridView onto the form, did you name it dgContacts?
 
Comment #10  (Posted by an unknown user on 09/09/2006)
Rating
it surely help the starting stage
 
Comment #11  (Posted by an unknown user on 09/12/2006)
Rating
Clear and Simple, very appropriate for beginner. Well Done!
 
Comment #12  (Posted by an unknown user on 09/20/2006)
Rating
David, vikram here

Simple, Consices and clear except for one thing man. You might wanna follow naming conventions since beginners tend follow the same names with their sample and from sample to their main projects. Other than its totally good article :)
 
Comment #13  (Posted by an unknown user on 10/08/2006)
Rating
David:

I have 6 books opened and lying all around me, and even though I've been programming access vba using ado for over 3 years, I couldn't find the necessary details to make the jump to ado .net.

Using the example that you provided, I connected to a database on sql server 2005 and got the datagrid to work when all of the code from the books I've been reading were generating errors or were exceptionally unclear.

You're doing a great job so far...

Please keep it up!

Thank You
Harold Morgan
Memphis, TN
 
Comment #14  (Posted by diallo on 10/20/2006)
Rating
please ,help me to have the solution of the exercice to "play cancel"
 
Comment #15  (Posted by an unknown user on 10/29/2006)
Rating
good job
 
Comment #16  (Posted by an unknown user on 11/13/2006)
Rating
Excellent for Newbie's
It's easyer to understand then "How do I" from Microsoft.With all their inbuild links.

Thanks a lot.

Henk, Netherlands
 
Comment #17  (Posted by an unknown user on 01/07/2007)
Rating
Hi! It will surely help the starting stage. Good Job!!

 
Comment #18  (Posted by an unknown user on 01/30/2007)
Rating
This is the clearest most simple yet educational example of how to connect to a database, you should write a book....
 
Comment #19  (Posted by an unknown user on 02/06/2007)
Rating
the article is easy to understand.
 
Comment #20  (Posted by M Ayaz on 02/07/2007)
Rating
I am using vb.net2005 and Office Xp. I downloaded the acces database that u provided and converted it to access 2002 format. I have followed the instructions in your tutorial to pin accuracy. When I press F5 an exception is thrown " Could not find installable ISAM". Can u please tell me what is wrong here?
 
Comment #21  (Posted by an unknown user on 03/01/2007)
Rating
very well
 
Comment #22  (Posted by an unknown user on 03/05/2007)
Rating
Great newbie stuff. I did this exercise using VC# 2005. But instead I used the dataview object. Which provokes me to ask: what is the difference between dataview and datagrid?
 
Comment #23  (Posted by David Jeavons on 03/05/2007)
Rating
Hi, thanks for your comment.

By DataView I assume you mean the new DataGridView control, this is an updated version of the DataGrid control for the .NET 2.0 Framework and provides more functionality than that found in the original DataGrid.

The reason I chose to use the DataGrid in this tutorial is that both users of .NET 1.1 and .NET 2.0 Frameworks would have access to this control, but of course, if you are using .NET 2.0 then there are not many reasons to reverting to the older DataGrid.
 
Comment #24  (Posted by an unknown user on 03/06/2007)
Rating
For a complete beginner, nice and simple to understand. Explained in easy to understand english.
 
Comment #25  (Posted by an unknown user on 03/08/2007)
Rating
It's a great introduction to database interfacing for beginners with minimal to zero knowledge in VB.NET programming.
 
Comment #26  (Posted by an unknown user on 03/27/2007)
Rating
This article has thorough explanations which made me feel comfortable with what I was doing. I am new to ADO.NET and I learned a lot from this article.
 
Comment #27  (Posted by an unknown user on 04/10/2007)
Rating
Is Part 2 out yet? Thanks. Worked Great. LTroxell
 
Comment #28  (Posted by Ronald on 04/17/2007)
Rating
Sorry, just wanted to follow on your tutorial but could not locate the example database you mentioned. can you help me with that anyone who found it?
many thanks.
 
Comment #29  (Posted by David Jeavons on 04/18/2007)
Rating
Hi Ronald

The database zip file can be found at the end of the article on page four.

Thanks
 
Comment #30  (Posted by an unknown user on 04/18/2007)
Rating
well if there is one thing i can say thats would be "you know what you are talking about"
.::Thanks::.
 
Comment #31  (Posted by an unknown user on 04/26/2007)
Rating
Very simple explanations.Keep it up.....So nice
 
Comment #32  (Posted by an unknown user on 05/09/2007)
Rating
I get an exception error at :

adapter.Fill(dt) - OleDb Exception "Not a valid file name"
 
Comment #33  (Posted by Steve on 05/10/2007)
Rating
I have resolved the above exception error. ( I had made a mod in the conn stmt to the path - oops)

The level of this tutorial fits with where I am perfectly.

Very Nice job
 
Comment #34  (Posted by an unknown user on 05/14/2007)
Rating
Thanks for great article.
 
Comment #35  (Posted by an unknown user on 06/08/2007)
Rating
Finally! Something made simple and methodical for a newbie to understand!
 
Comment #36  (Posted by an unknown user on 06/14/2007)
Rating
Easy and short.Thanks.....!
 
Comment #37  (Posted by an unknown user on 07/03/2007)
Rating
David is an excellent writer and instructor. If he hasn't written any books yet, he definetly should.
 
Comment #38  (Posted by an unknown user on 07/31/2007)
Rating
Clearly understandable..
Follow the rules and it will work for sure!!!
Thanks
 
Comment #39  (Posted by an unknown user on 08/23/2007)
Rating
its preety good for beginers like us but explain y v can't give ne name to r database
 
Comment #40  (Posted by an unknown user on 09/14/2007)
Rating
Very nice article for newbees

 
Comment #41  (Posted by an unknown user on 09/28/2007)
Rating
Clear, consise and great explanations
 
Comment #42  (Posted by TC on 09/30/2007)
Rating
Very good article.
Very good writting skills, clean and to the point
 
Comment #43  (Posted by bros_cchkout on 10/04/2007)
Rating
Good
 
Comment #44  (Posted by an unknown user on 10/05/2007)
Rating
Just the sort of stuff us newbees need. Thank you for taking the time to write this article.
 
Comment #45  (Posted by an unknown user on 10/13/2007)
Rating
Thanksfor the article... Simple and Nice... Good Job...
 
Comment #46  (Posted by an unknown user on 11/24/2007)
Rating
Thanks. I hope there is one that deals with mysql and password protected access. Nice and simple with great explanations.
 
Comment #47  (Posted by an unknown user on 12/10/2007)
Rating
I have been trying FOR DAYS to figure out what you so eloquently stated in a few sentences. THANK YOU for saving my sanity!!! :)
 
Comment #48  (Posted by Touradg on 12/24/2007)
Rating
Very nice job sir.Your great article caused me to start loving databases.
Very simple explanation.thank you.
I just had problem with get and set.but iw ill digg into it soon.
 
Comment #49  (Posted by an unknown user on 12/27/2007)
Rating
For a beginner this artical is very easy to understand.
 
Comment #50  (Posted by an unknown user on 01/01/2008)
Rating
Very Informative for Beginers
 
Comment #51  (Posted by an unknown user on 01/20/2008)
Rating
quite interesting..thank you
 
Comment #52  (Posted by joseph on 05/19/2008)
Rating
nice site dude
 
Comment #53  (Posted by john on 05/19/2008)
Rating
interesting site man
 
Comment #54  (Posted by Jesmond Navarro on 06/03/2008)
Rating
You're the Best, mate. Better than Microsoft's Help!
 
Comment #55  (Posted by an unknown user on 06/03/2008)
Rating
Well Done Man
 
Comment #56  (Posted by SxWPLOEqDBYWTbfrO on 06/05/2008)
Rating
tickets_5.txt;2;2
 
Comment #57  (Posted by an unknown user on 07/22/2008)
Rating
hi your book is the worst one inmy whole life that i'v read
 
Comment #58  (Posted by nick on 07/27/2008)
Rating
vpq21h hi! hice site!
 
Comment #59  (Posted by nick on 07/27/2008)
Rating
5v4b4k hi! hice site!
 
Comment #60  (Posted by nick on 07/28/2008)
Rating
FD1cna hi! hice site!
 
Comment #61  (Posted by nick on 07/28/2008)
Rating
ndPZiH hi! hice site!
 
Comment #62  (Posted by nick on 07/29/2008)
Rating
O6CJJI hi! hice site!
 
Comment #63  (Posted by nick on 07/29/2008)
Rating
v3EthK hi! hice site!
 
Comment #64  (Posted by orolocdomle on 07/31/2008)
Rating
elrolc4
 
Comment #65  (Posted by orolocdomle on 07/31/2008)
Rating
elrolc4
 
Comment #66  (Posted by adult on 08/16/2008)
Rating
hi great site 10x
 
Comment #67  (Posted by an unknown user on 08/24/2008)
Rating
Gud job
 
Comment #68  (Posted by Ranjan on 08/29/2008)
Rating
Very good project. It helps me a lot.

Thanks a lot
 
Comment #69  (Posted by RytMigOkfPQA on 09/06/2008)
Rating
6vytSd spam_15.txt;5;10
 
Comment #70  (Posted by kate on 10/19/2008)
Rating
sweet site thx
 
Comment #71  (Posted by himamaster on 11/25/2008)
Rating
SXRUvm himamaster hi
 
Comment #72  (Posted by an unknown user on 01/17/2009)
Rating
it is very useful for beggineers.
 
Comment #73  (Posted by an unknown user on 01/21/2009)
Rating
Very interesting article; Please Can You Send Me A Tutorial On Generating Random Question unto a form. My Email is Chiztorismo@Yahoo.com Or Chiztorismo@Gmail.com
I will Be Very Glad,I Love Your Article, I am Just an Upcoming VB Programer.
 
Comment #74  (Posted by zibex on 01/21/2009)
Rating
4gBQrT hi! nice site!
 
Comment #75  (Posted by HflYrKfS on 01/23/2009)
Rating
621b36eb56
 
Comment #76  (Posted by qFgyLfxgX on 02/06/2009)
Rating
81c798ecb5
 
Comment #77  (Posted by sBuoRKOPjpnzDZ on 02/06/2009)
Rating
26c0f2c32e
 
Comment #78  (Posted by an unknown user on 02/07/2009)
Rating
just excellent
 
Comment #79  (Posted by cGVFjqJHmFhPAB on 02/13/2009)
Rating
979559750c
 
Comment #80  (Posted by an unknown user on 02/26/2009)
Rating
useful
 
Comment #81  (Posted by noor on 05/04/2009)
Rating
great code , it solve my problem , well done
 
Comment #82  (Posted by an unknown user on 06/12/2009)
Rating
It is very useful..
 
Comment #83  (Posted by on 10/11/2009)
Rating

 
Comment #84  (Posted by Dzqegzur on 11/05/2009)
Rating
comment6
 
Comment #85  (Posted by Icgzyloq on 11/05/2009)
Rating
comment3
 
Comment #86  (Posted by Ynfbgtbx on 11/05/2009)
Rating
comment3
 
Comment #87  (Posted by Hhkllihl on 11/06/2009)
Rating
comment1
 
Comment #88  (Posted by Hhkllihl on 11/06/2009)
Rating
comment1
 
Comment #89  (Posted by Fgqwzjsj on 11/06/2009)
Rating
comment3
 
Comment #90  (Posted by Vmyaozti on 11/06/2009)
Rating
comment5
 
Comment #91  (Posted by Tfnbaqbn on 11/06/2009)
Rating
comment6
 
Comment #92  (Posted by Vywnblbd on 11/07/2009)
Rating
comment3
 
Comment #93  (Posted by Mwszkiih on 11/07/2009)
Rating
comment1
 
Comment #94  (Posted by Dabslske on 11/07/2009)
Rating
comment4
 
Comment #95  (Posted by Yrbsnflz on 11/07/2009)
Rating
comment6
 
Comment #96  (Posted by Bwktieog on 11/07/2009)
Rating
comment3
 
Comment #97  (Posted by Sfajqkmi on 11/08/2009)
Rating
comment6
 
Comment #98  (Posted by Wfnezhak on 11/08/2009)
Rating
comment5
 
Comment #99  (Posted by Kjeihnyf on 11/08/2009)
Rating
comment3
 
Comment #100  (Posted by Yyipdtex on 11/08/2009)
Rating
comment4
 
Comment #101  (Posted by Pampjgaf on 11/09/2009)
Rating
comment5
 
Comment #102  (Posted by Teilvkru on 11/09/2009)
Rating
comment5
 
Comment #103  (Posted by Ruspxzhj on 11/09/2009)
Rating
comment6
 
Comment #104  (Posted by Kaikqowr on 11/09/2009)
Rating
comment5
 
Comment #105  (Posted by Ltnpkarp on 11/09/2009)
Rating
comment5
 
Comment #106  (Posted by Kpvcdjpa on 11/10/2009)
Rating
comment2
 
Comment #107  (Posted by Pufiudxp on 11/10/2009)
Rating
comment5
 
Comment #108  (Posted by Gfaiqgax on 11/10/2009)
Rating
comment1
 
Comment #109  (Posted by Hqmksztv on 11/10/2009)
Rating
comment6
 
Comment #110  (Posted by Gtkwfrxj on 11/10/2009)
Rating
comment2
 
Comment #111  (Posted by Lruombyy on 11/11/2009)
Rating
comment1
 
Comment #112  (Posted by Ahdzozmr on 11/11/2009)
Rating
comment6
 
Comment #113  (Posted by Bxxmfhhp on 11/11/2009)
Rating
comment2
 
Comment #114  (Posted by Nkvqfhcf on 11/11/2009)
Rating
comment2
 
Comment #115  (Posted by Vmfkcamz on 11/11/2009)
Rating
comment2
 
Comment #116  (Posted by Ramhoqea on 11/11/2009)
Rating
comment3
 
Comment #117  (Posted by Oubudgor on 11/11/2009)
Rating
comment5
 
Comment #118  (Posted by Ejjjifgh on 11/12/2009)
Rating
comment2
 
Comment #119  (Posted by Lcsrufzh on 11/12/2009)
Rating
comment1
 
Comment #120  (Posted by Ngaqkmbt on 11/12/2009)
Rating
comment5
 
Comment #121  (Posted by Jwchwoyi on 11/12/2009)
Rating
comment6
 
Comment #122  (Posted by Nrzrxfcf on 11/12/2009)
Rating
comment3
 
Comment #123  (Posted by Nrzrxfcf on 11/12/2009)
Rating
comment3
 
Comment #124  (Posted by Ixdzqool on 11/12/2009)
Rating
comment1
 
Comment #125  (Posted by Ixdzqool on 11/12/2009)
Rating
comment1
 
Comment #126  (Posted by Odvtojun on 11/12/2009)
Rating
comment2
 
Comment #127  (Posted by Ytvabdcu on 11/12/2009)
Rating
comment2
 
Comment #128  (Posted by Ymrgkldb on 11/12/2009)
Rating
comment5
 
Comment #129  (Posted by Sgitbpeq on 11/12/2009)
Rating
comment4
 
Comment #130  (Posted by Cbxxhqqj on 11/12/2009)
Rating
comment1
 
Comment #131  (Posted by Riupkfhu on 11/13/2009)
Rating
comment5
 
Comment #132  (Posted by Gogktrak on 11/13/2009)
Rating
comment4
 
Comment #133  (Posted by Vcqvbwrc on 11/13/2009)
Rating
comment4
 
Comment #134  (Posted by Pgyblfvv on 11/13/2009)
Rating
comment2
 
Comment #135  (Posted by Pgyblfvv on 11/13/2009)
Rating
comment2
 
Comment #136  (Posted by Tppudesq on 11/14/2009)
Rating
comment3
 
Comment #137  (Posted by Taxskmqm on 11/15/2009)
Rating
comment4
 
Comment #138  (Posted by Jpaewnes on 11/15/2009)
Rating
comment4
 
Comment #139  (Posted by Sbidtfjp on 11/15/2009)
Rating
comment3
 
Comment #140  (Posted by Oygumrvg on 11/15/2009)
Rating
comment3
 
Comment #141  (Posted by Eiclrzed on 11/15/2009)
Rating
comment2
 
Comment #142  (Posted by Eiclrzed on 11/15/2009)
Rating
comment2
 
Comment #143  (Posted by Wnakbctn on 11/15/2009)
Rating
comment1
 
Comment #144  (Posted by Cjrvmdjh on 11/15/2009)
Rating
comment1
 
Comment #145  (Posted by Cbholcut on 11/15/2009)
Rating
comment3
 
Comment #146  (Posted by Hhoibtav on 11/15/2009)
Rating
comment3
 
Comment #147  (Posted by Bjnodghi on 11/16/2009)
Rating
comment2
 
Comment #148  (Posted by Bjnodghi on 11/16/2009)
Rating
comment2
 
Comment #149  (Posted by Bjnodghi on 11/16/2009)
Rating
comment2
 
Comment #150  (Posted by Dbsrdpyv on 11/16/2009)
Rating
comment4
 
Comment #151  (Posted by Qnqvnutc on 11/16/2009)
Rating
comment5
 
Comment #152  (Posted by Uduqotba on 11/16/2009)
Rating
comment3
 
Comment #153  (Posted by EVAFlQioOpuWrDEj on 11/17/2009)
Rating
270_98.txt;8;12
 
Comment #154  (Posted by ohSURZAKcBZRsNbb on 11/18/2009)
Rating
270_109.txt;8;12
 
Comment #155  (Posted by tFxckGBcUq on 11/18/2009)
Rating
270_110.txt;8;12
 
Comment #156  (Posted by pyOZitJItpMcmB on 11/18/2009)
Rating
270_111.txt;8;12
 
Comment #157  (Posted by QwKhEypMAqCPOKHC on 11/18/2009)
Rating
270_112.txt;8;12
 
Comment #158  (Posted by GaPKSXnXypzA on 11/18/2009)
Rating
270_113.txt;8;12
 
Comment #159  (Posted by GrlAvsaBOjhTP on 11/18/2009)
Rating
270_114.txt;8;12
 
Comment #160  (Posted by dWDJumbjfPHPdOhhuyw on 11/18/2009)
Rating
270_115.txt;8;12
 
Comment #161  (Posted by RdkmNZWmeXgDHgicw on 11/18/2009)
Rating
270_116.txt;8;12
 
Comment #162  (Posted by ZvQKWPHhVjTybFks on 11/19/2009)
Rating
270_117.txt;8;12
 
Comment #163  (Posted by jGkLBEqhwGko on 11/19/2009)
Rating
270_118.txt;8;12
 
Comment #164  (Posted by ZiAIlhLZdsAinVIBH on 11/19/2009)
Rating
270_119.txt;8;12
 
Comment #165  (Posted by SasDer on 11/24/2009)
Rating
Your site is very convenient in navigation and has good design. Thanks!: URLsWithURL
 
Comment #166  (Posted by metabolism via the cytochrome P450 isozyme CYP2D6 on 11/27/2009)
Rating
It is a member of the site.: URLsWithURL
 
Comment #167  (Posted by Feoplf on 11/28/2009)
Rating
Here is intresting people… Lets talk!: URLsWithNothing
 
Comment #168  (Posted by an unknown user on 12/21/2009)
Rating
Its good but for a beginner its still complex thing becoz it assumes many things like the overloading property of the adapter and polymorphism.
 
Comment #169  (Posted by SmithJ on 05/20/2010)
Rating
Oi2lor Lol lol lool lol ha-ha! Lol lol lol?
 
Comment #170  (Posted by gfdggdfg on 10/12/2010)
Rating
QukysW pepyaka
 
Comment #171  (Posted by Zaiyah on 06/28/2011)
Rating
Real brain power on display. Thanks for that asnewr!
 
Comment #172  (Posted by an unknown user on 01/27/2012)
Rating
This is how tutorials SHOULD BE!

 
Sponsored Links