Article Options
Premium Sponsor
Premium Sponsor

 »  Home  »  Data Programming  »  ADO.NET  »  Getting Started with ADO.NET
Getting Started with ADO.NET
by Gurneet Singh | Published  02/06/2002 | ADO.NET | Rating:
Gurneet Singh

Gurneet Singh is a Senior Software Engineer for Herosoft, India, with 4 years of experience in Microsoft Technologies. He has designed and developed wide range of applications. He is experienced in Visual Basic, ASP, SQL Server, Oracle, COM/DCOM, MTS.

Gurneet's focused these days on Visual Basic.NET and ASP.NET in general, building database applications and distributed applications using VB.NET and ASP.NET.

 

View all articles by Gurneet Singh...
Getting Started with ADO.NET

When I started my search on the .NET Platform from Microsoft a few months ago I was pretty confused about the whole idea of .NET, what exactly it is. For any Visual Basic programmer the most basic thing and for most of us the most important thing to run any of our applications is Database Access and yes it means a lot to an experienced VB programmer.

When I use the word confused the very idea of using it is that within a short span of 3-4 years Visual Basic has seen itself go so fast that we don't even remember when we started using DAO's, RDO's, ADO's and Microsoft is back again with another dish in the bowl which is served with the name ADO.NET.

Coming back to the first data access model that was called Data Access Objects (DAO) created for local databases like MS-Access with the built in Jet Engine. Needless to mention you could have used it to access any Server Databases but the functionality and the performance were issues.

The next in the line was the Remote Data Objects (RDO) and then DO which were both designed for Client Server and Distributed Architecture but it was not too late when ADO completely took over and RDO was not seen for a long time.

And now for the .NET framework ADO has been redesigned and enhanced for use on the Internet and distributed architectures. The question every developer will have at this point will be "hey come on isn't ADO sufficient to give me quite a lot?" On this question, an experienced VB or ASP developer might answer "it is a good architecture, but has issues when you work on distributed architectures and that too of the Internet" e.g. one major problem with ADO is that a recordset that is a COM object cannot be easily passed around the network, they cannot penetrate firewalls.

I will be writing a series of articles on ADO.NET and how we can leverage the power of this little complex but a wonderful technology so as to make our applications more scalable, robust and of course you can never forget the performance of the applications. The.NET era of application development ADO.NET is catered with large number of objects to carry very specific functional tasks and they solve the problems that were present with ADO.

ADO.NET can be used for accessing many kinds of data sources. In ADO data was accessed with OLEDB providers, which can be written for any kinds of data, stores such as flat files and of course the RDBMS. We are aware of how XML makes things easy and ADO.NET leverages the power of XML by converting all the data into XML and then using it for all Database related operations.

ADO.NET provides two kinds of Objects or if I am not wrong we can call them providers. One of which is OLEDB and the other is the SQL server. If SQL server is your database then ADO.Net provides you with the set of objects that bypass the OLEDB provider and directly access the SQL server tabular data stream. This direct access to SQL server's data stream increases the applications performance. If you are using the MS Access, Oracle, FoxPro etc you have with you completely a different set of classes that encompass the same functionality as SQL server optimized objects but through an OLEDB provider.

To access the ADO.NET classes you have to import some namespaces that hold the objects, which are required to carry out our database level operations.

The namespaces that are required are

System.Data

This namespace holds all the objects that are required to access and store data in any kind of a RDBMS. Dataset, DataReader and DataRelation are a named few that are used to create the relation data stores in the memory

In the code window they will be imported as

Imports System.Data

  • DataSet
  • DataTable
  • DataRow
  • DataRelation

Replacing Recordsets

Microsoft in ADO.NET no longer supports the good old recordset class. No worry, they still exist for backward compatibility but their use for future developments is discouraged if for few server side operations which will be still superior with recordset class. Recordset has been replaced with what we call DataSets, which is a collection of mini recordsets and relations between them. Datasets are just local copies of the relational data that lies on the server and is used for local processing, whether on a client, Web server or a remote PC. All operations are carried on the local copy of the data with virtually no connection to the database at all.

This reminds us the advantage of disconnected recordsets. When all the operations get completed on the local data the whole bunch is submitted to the original database for a commit.

In addition to Datasets there is another class that is available in ADO.NET, this is called the DataReader and seen as read only recordset with a forward only cursor.

Imports System.Data.SQLClient

Any kind of manipulation with our favorite database the SQL server use the set of objects in this class

  • SQLConnection - Represents the connection to the SQL Server Database for DataSet object
  • SQLCommand - Used to execute the T-SQL commands such as stored procedures, functions etc
  • SqlCommandBuilder - Automatically generates the commands in SQL Adapter
  • SQLDataSet
  • SQLDataReader - Returns read only, forward only cursor
  • SQLDataAdapter - Used to map data from SQL server to a dataset for DML operations
  • SqlParameter - Similar to parameter objects in ADO.Represents a parameter to SqlCommand

Imports System.Data.OleDb

Contains the objects that will help us accessing the data through OLEDB provider. These objets have the same properties and methods as the SQLClient space

  • OleDbConnection
  • OleDbCommand
  • OleDbDataSet
  • OleDbDataReader
  • OleDbDataAdapter

OleDb and the SQLClient namespaces are built almost alike as you can just see from the names the commonality between them.

I will give below a very simple example of using a managed Provider (oledb and SQL Providers are both known as the managed providers in the ADO.NET architecture)

Imports System.Data
Imports System.Data.SqlClient

Module Module1

    Sub Main()

        Dim connSql As SqlConnection
        Dim cmSql As SqlCommand

        Dim dremp As SqlDataReader
        connSql = New SqlConnection(
            "server=webserver;uid=sa;pwd=;database=license")
        cmSql = New SqlCommand("procename"connSql)
        cmSql.commandtype = CommandType.StoredProcedure
        Try
            connSql.Open()
            dremp = cmSql.ExecuteReader()
            Do While dremp.Read()
                Console.WriteLine(dremp("ename").ToString())
            Loop
        Catch err As SqlException
            Console.WriteLine(err.ToString())
        Finally
            connSql.Close()
        End Try

    End Sub

End Module
Generated using PrettyCode.Encoder

I hope the above piece of code works fine with your machine if you have a license database on the SQL server called Web server and create a procedure called procname that selects just names of the employees from the emp table.

In my next article I will be covering how to read your data into a VB.Net page using a Data grid and some more features of the ADO.NET and how we can pull the data into an ASP.NET page with almost no changes to our code in VB.NET.

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.09090909090909 out of 5
 44 people have rated this page
Article Score33588
Comments    Submit Comment

Comment #1  (Posted by Ashish on 04/15/2002)

This is the very informative article good for future builind up knowledge on ADO.Net vis-a-vis other object earlier exists.
 
Comment #2  (Posted by Grammer Police on 05/05/2002)

This is the most poorly written article I have ever seen on this board. The grammer is atrocious! I'm trying to learn ADO.NET and I don't want to have to worry about wether or not I am interpreting the authors laughable writing correctly.

Please Mr. Editor - read articles before allowing them to be posted.


 
Comment #3  (Posted by Shruti jain on 08/01/2002)

Very good article explains very well differences between ADO and ADo.NET . Good programmer do not care about grammer but designer may so designers don;t even read these articles.
 
Comment #4  (Posted by Spelling Police on 08/31/2002)

Hey, 'Grammar Police', clean your own house first. It's not spelled "wether" !
 
Comment #5  (Posted by Abubakar on 09/09/2002)

Really a greate topic and artical.
 
Comment #6  (Posted by an unknown user on 10/10/2002)


 
Comment #7  (Posted by Anuj Dixit on 12/23/2002)

Good Artical
 
Comment #8  (Posted by Gurmeet on 08/27/2003)

Thanx,..

I am new to Dot Net .,I was searching such kind of article...
It was very informative and well explaned..

 
Comment #9  (Posted by Michael on 11/27/2003)

Good stuff covers all the important point and that what matter
I know know a bit more about ado .net
Thanks

 
Comment #10  (Posted by Mohammed on 11/27/2003)

Thank you for your efforts. Good Artical
 
Comment #11  (Posted by amarjeet on 08/11/2004)

this article is very useful and clear .
i need some information about connevtivity bet vb.net and sqlbase using ado.net lookinf forward ur reply

 
Comment #12  (Posted by .NET Developer on 09/20/2004)

Some people like GRAMMER POLICE is simply disturbing the Authors. These guys have a very disgraceful attitude for other people who wants to do something. This is a Tech Article not an English Language test. As long as we understand what the author wants to say it should be fine for all of us. Thanks.
 
Comment #13  (Posted by Grammar Police Idiot on 09/26/2004)

That guy who calls himself the Grammar Police really is a tosser. I believe that the article is one of the very few which explains in simple terms to beginners the correct syntax and functionality for ADO.NET. I get the feeling that the reason he was being so rude is that he couldn't grasp it himself! Beginner? Don't bother trying to learn more - we can do without ignorant people like you.
 
Comment #14  (Posted by Grammar Policegirl on 12/14/2004)

I would like to point out to "GrammerPolice" that there is no 'e' in the word grammar.
 
Comment #15  (Posted by an unknown user on 02/08/2005)
Rating
it is easily understandable by a new user to .net
 
Comment #16  (Posted by an unknown user on 03/24/2005)
Rating
it's good.it will be useful for beginers.
 
Comment #17  (Posted by Now I Can Do It on 04/07/2005)
Rating
Very direct, concise, accurate - very much appreciated.
 
Comment #18  (Posted by ilaw on 04/27/2005)
Rating
Good work! every beginner would surely get benefit out of it and thanks as well coz i am one of them!!
 
Comment #19  (Posted by an unknown user on 05/16/2005)
Rating
I apriciate this presentation and peace od code
 
Comment #20  (Posted by an unknown user on 06/02/2005)
Rating
Excellent for beginner in VB.net like me, very easy to understand
 
Comment #21  (Posted by an unknown user on 06/07/2005)
Rating
this is a good article for programming students like me.
 
Comment #22  (Posted by Passing programming Student on 06/07/2005)
Rating
This is a good article for a Programming student like me.
 
Comment #23  (Posted by an unknown user on 06/16/2005)
Rating
this is complete crap...until now i still haven't seen how to creat stored procedures in MS Access using ASP.Net
 
Comment #24  (Posted by an unknown user on 06/16/2005)
Rating
this is complete crap...until now i still haven't seen how to create and used stored procedures in MS Access using ASP.Net
 
Comment #25  (Posted by an unknown user on 06/22/2005)
Rating
Missing DataTabla, DataView, DataRow
 
Comment #26  (Posted by an unknown user on 07/03/2005)
Rating
I m a beginner . Can someone tell me a good article or an e-book that help me develop a small windows appication for MS access in VB.net
 
Comment #27  (Posted by Anvar batcha on 09/12/2005)
Rating
Nice article and really helps well for the beginners
 
Comment #28  (Posted by an unknown user on 09/20/2005)
Rating
THIS IS TOO GOOD FOR BEGINNERS
A GOOD INTRO TO ADO.NET
 
Comment #29  (Posted by an unknown user on 09/26/2005)
Rating
As a beginner I looked for some detail articles on .NET,this one I found most useful and easy to digest. Thank you a lot.

Amitava Dey
 
Comment #30  (Posted by an unknown user on 10/10/2005)
Rating
Waiting for more....
 
Comment #31  (Posted by an unknown user on 10/10/2005)
Rating
you said clearly
 
Comment #32  (Posted by an unknown user on 10/11/2005)
Rating
Very helpfull info for beginners.
 
Comment #33  (Posted by Sujatha on 11/19/2005)
Rating
Very good stuff for the beginners.
 
Comment #34  (Posted by an unknown user on 12/21/2005)
Rating
Too much explanation about the past & little about the present.
 
Comment #35  (Posted by Nikhil Sarin on 03/08/2006)
Rating
Gurneet!
Don't bother about the pathetic words that has used in his comment. I really appreciate your effort. This article is superb 'n' a request to you:- "Please submit all your articles whatever you step next in your .net life. A gr8 job.
 
Comment #36  (Posted by an unknown user on 03/29/2006)
Rating
Great Job. Gurneet keep on writing good stuffs like this
 
Comment #37  (Posted by an unknown user on 04/22/2006)
Rating
it gives the simple n detailed outlook
 
Comment #38  (Posted by an unknown user on 05/23/2006)
Rating
PERFECT
 
Comment #39  (Posted by an unknown user on 07/18/2006)
Rating
Clear and Concise!
 
Comment #40  (Posted by IP on 07/26/2006)
Rating
SQLDataSet, OleDbDataSet -As I read in the articles elsewhere/before; DataSet does not preceed with Sql or Oledb or Odbc etc. . Is it a wrong information in this article by puting these things in article.
 
Comment #41  (Posted by an unknown user on 09/13/2006)
Rating
good clear coding with comment which explains the code and it's meaning
 
Comment #42  (Posted by an unknown user on 01/25/2007)
Rating
I like your article and examples. You are so GREAT. David. Thanks for the time. I am waiting for more your articles.
 
Comment #43  (Posted by an unknown user on 02/25/2007)
Rating
Jeez - ADO.NET?? I agree with the rapid transition from dao to rdo to ado and now to ado.net... I'm still having trouble with the object oriented VB code!
 
Comment #44  (Posted by an unknown user on 03/04/2007)
Rating
Very useful artikal
 
Comment #45  (Posted by an unknown user on 06/17/2007)
Rating
I've just spent two days working with a book that forgot all about the SQLCommand arguments
Obviously nothing worked.
 
Comment #46  (Posted by an unknown user on 08/03/2007)
Rating
VERY NICE. . Thanks a lot... keep continue......


Excellent
 
Comment #47  (Posted by an unknown user on 11/12/2007)
Rating
Is a really very good article as it shows the difference between recordset and dataset, for the one who knows vb6 and going to start programming in vb.net.
 
Sponsored Links