Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.

Reply With Quote
  #2 (permalink)  
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
Reply With Quote
  #3 (permalink)  
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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:31 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.