Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
| Search | Today's Posts | Mark Forums Read
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 8th, 2007, 07:56 AM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default need guideline about connect to DB

Hi
I am new to programming and currently I try to write c# class to view/insert/update/delete infomation in sql server database by GridView control. What classes do I have to you such as sqlDataSource, sqlDataReader, Dataset,....so on. I seem to be confused by these words. If I want to use sqlDataReader, I have to use it with sqlConnection and sqlCommand? Pls help to clearify.

 
Old May 9th, 2007, 04:30 AM
Authorized User
 
Join Date: Dec 2004
Location: Swindon, Wilts, United Kingdom.
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DZukiewicz
Default

You will always need a SqlConnection and SqlCommand.

The SqlConnection establishes the network connection to the database.
The SqlCommand contains information about what the database should process.

The question that remains is "Should I remain connected when processing the query?". This then splits your query into 2 camps:

1) Connected.
2) Disconnected.

The "Connected" classes mean that the connection is maintained, and you would programatically retrieve columns. This is known to be faster, although slightly more code is required. You also have to open and close connections yourself.

These are in the form of DataReader's.

The "Disconnected" classes open the connection, download the whole result of the query to a DataSet and disconnects by itself.. no need to open and close the connections yourself.

These are in the form of DataAdapter's.

I picture the DataSet as a database in memory. A dataset can have tables (DataTable) and each table consists of rows (DataRows) and columns (DataColumns). You can also define relationships between tables (DataRelations), should you wish to cross reference data.

.NET 2.0 helps ease the process by generating DataSets specific to your query. So for example, say you write a stored procedure to get all of the customers in a database, you can tell .NET (in design time) to create a DataSet which matches the data returned from this stored procedure, which is type-safe and named with the column names from your database.

There are plenty of resources on the net discussing the differences between connected and disconnected ADO .NET. Once you start using these classes, you'll wonder how you ever got them confused :-)

Hope this helps,

Dominic
 
Old May 9th, 2007, 11:57 AM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you. Your explaination really help me organize the picture of ADO.NET.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to connect to DB rtr1900 VB Databases Basics 4 December 5th, 2006 03:36 PM
Connect to DB hernann C# 2005 2 July 31st, 2006 05:06 PM
Connect two or more DB at the same time?? rtr1900 Classic ASP Databases 0 May 31st, 2006 06:32 AM
connect to sql db jopay Visual C++ 0 January 12th, 2005 05:17 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.