ADO .Net Data Access in C#

Download Source: DotNetData.zip

The example defines the prototype for accessing the data through ADO .Net objects in C#.

For any given database table there are 4important operations while working with relational tables anddatabases. The 4 different operations, which can be done on thedatabase, are ADD, UPDATE, DELETE and SELECT.

This prototype gives the users (especiallythose who come from writing COM object) the idea of a differentarchitecture in .Net world about executing the database operationsthrough store procedures just like people used to do it in VB COMobjects. To tell you the truth I found .Net much more simpler and moreappealing and the whole prototype is written in matter of 5-6 hrs. Alsoplease excuse me for using VB like names in C# for the variables. Alsoexcuse with my bad language. But hopefully users can understand myprototype.

I have used SQL 2000 desktop edition andVisual .Net Studio Beta 2 AND C# to write these prototype. In thisexample I am using database "pubs" which comes standard example withSQL server installation. Inside pubs database I have used the alreadyexisting table called "Stores". One can use any database or table butwould have to make necessary changes in order to make the code work.

My connection string look like this

string strCn = @"uid=sa;pwd=;server=" + strServer + ";database=" + strDB;

Where

strServer = "Name of the users Machine where DB resides."

strDB = "Name of the database "

For example for my PC ?

strServer = "COMP2\NETSDK"

str DB = "pubs"

Please not that \NETSDK is created when .NetStudio is installed on the machine. One might use machine name asmachine name in my case "COMP2" as Server name. But it doesn?t worksince the databases are found under "COMP2\NETSDK" server. One can findthe SQL server under Server Explorer in .Net VS.

Also use \ for creating a back slash. Single"\" is considered as an escape sequence in C#. For more informationplease refer to C# reference books.

To make things simpler I am only concentratingthe business objects and data services. I have used windows form toexecute this procedure through the buttons on the form.

This prototype has following objects.

Data Services ? (Store Procedures.)

I have written 4 store procedures, whichencapsulates the functionality of the common database operation that isSELECT, DELETE, INSERT and UPDATE.

Business Objects

Namespace ? "DotNetData" ? I just used this name since I like it?

User can change the namespace to any thing they like.

DotNetData.DBFunctions ? C# class library "DBFunctions" is a utility object that encapsulates the DB Operations.

In COM world this particular object isessentially a transaction object, which is interfacing the database andis implemented inside the other COM objects.

DotNetData.Stores ? C# class library "Stores"contains a functions which implements functions from class DBFunctions.Also defines the different operation on the database table "Store".

Please note that business objects are dividedinto 2 objects. DBFunctions would be common denominator object forother class library such as class library Stores. Developer need toreference class DBFunctions while writing methods of class library suchas Stores.

Windows Form "frmStore" ? I have used DataGrid to show the retrieved data and Button objects to call andimplement different functions from class library "Stores"

Twitter Digg Delicious Stumbleupon Technorati Facebook Email

No comments yet... Be the first to leave a reply!