Article Options
Premium Sponsor
Premium Sponsor

 »  Home  »  .NET Newbie  »  ADO.NET for Beginners Part One  »  An Introduction to the System.Data object
 »  Home  »  Data Programming  »  ADO.NET  »  ADO.NET for Beginners Part One  »  An Introduction to the System.Data object
ADO.NET for Beginners Part One
by David Jeavons | Published  07/12/2006 | .NET Newbie ADO.NET | Rating:
An Introduction to the System.Data object

Before we start writing any code to connect to the database, it is important to understand some of the objects that you will be using and their storage locations within the Namespace hierarchy.

In order to start working with databases you first need to ensure that you have a reference to the System.Data object. To do this, select the Add Reference menu option from the Project menu and scroll down to the System.Data entry. Once you have added this reference, we can then take a closer look at what is offered via this object and also look at some of the methods we will be using in this part of the article.

Now, some of you may already know this, but there is a very nice tool in Visual Studio called the Object Browser. This tool isn't new to Visual Studio.NET but has been available in versions of Visual Basic as far back as I can remember. To access this tool, select the Object Browser menu option from the View menu. The Object Browser allows you to look at all objects referenced by your application and to drill down and look at the methods and properties that are exposed by those objects. Well designed objects will also have information in the form of remarks and descriptions that you can view when selecting a method or property.

So, with the Object Browser open, you should see the System.Data entry. If you expand the node you will see the available objects exposed by the System.Data object. The first point of interest is the sub node System.Data, this object houses all of the generic data objects that you will undoubtably use when working with databases. These objects include the DataSet, DataTable and DataView objects that you may already be familiar with.

The next point of interest are the different data provider objects that are available, such as System.Data.OleDb and System.Data.SqlClient. The System.Data.OleDb object contains objects that allow you to work with database that are oleDb compatible, such as Microsoft Access and mySQL. The System.Data.SqlClient object is an object that is specifically written to work with Microsoft SQL Server databases. There is also an System.Data.Odbc object should you need to work with databases via ODBC. As this part of the article is using an Microsoft Access database, we will concentrate on the System.Data.OleDb object from this point on, but when we reach Part Three of this article (using Microsoft SQL Server) you will see that the System.Data.SqlClient object is very similar to the System.Data.OleDb object).

If you expand the System.Data.OleDb node you will be presented with a list of the objects exposed. For this section of the tutorial we will be using the OleDbConnection and the OleDbDataAdapter objects to connect and retrieve an initial set of data from the database. By selecting the OleDbConnection node entry you will see the available methods and properties of this object as indicated in the following screen shot:


The OleDbConnection object in the Object Browser

As you can see in the above screen shot, I have selected the New(string) method, this is an overloaded constructor which as the summary states, initialises an instance of the connection object using a specified connection string.

If this is the first time that you have used the Object Browser, I recommend that you take some time to get to know it as it will undoubtedly aid you in your work.

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 stciwyekxu on 01/23/2008)
Rating
Hello! Good Site! Thanks you! pqcolpkoea
 
Sponsored Links