index > .NET Framework Data Access and Storage > DataSet Vs DataReader????

DataSet Vs DataReader????

When using the dataset, is this code snippet the same as when using the SqlDataReader and doing like this



while dr.Read()
string value = ""
Value = dr["database value"].ToString()

when using the Dataset Is the code assigning the values to the actual rows of data with all the information that is held within the dataset..So since this Dataset has a collection of tables and rows is it safe to say that u are accessing the data elements like this.....



System.Data.DataSet ds = SqlHelper.ExecuteDataset(
SqlHelper.ConnectionString,
"CustomerNotes_SelectByCustomerNoteId",
new object[] {CustomerNoteId });
CustomerNote myCustomerNote =
new CustomerNote();
myCustomerNote._CustomerNoteId = CustomerNoteId;
myCustomerNote._CustomerId = (
int)ds.Tables[0].Rows[0]["CustomerId"];

myCustomerNote._Date = (DateTime)ds.Tables[0].Rows[0]["Date"];
myCustomerNote._Note = (
string)ds.Tables[0].Rows[0]["Note"];
return myCustomerNote;




Give youself a round of applause!!
Tryin2Bgood

DataSet holds information about the results, schema information also and allows editing of the table directly, then finally being able to commit changes to the database using the DataAdapter.

A SqlDataReader is different, it is a fast forward only reader bringing back the results from SQL, just the values itself, nothing about the Schema information or anything hence why its faster than doing a Fill() on a dataset using a SqlDataAdapter.

SqlDataReader is ideal if you just need to get values without caring about the data types and relationships etc...

DataSet can also be used to bind to a databindable component, having the ability to modify the data that exists in the dataset datatable.

does this answer your question? didn't quite understand what you were asking




Need 2 be back @ MS - MS All the way! Follower since 1995 MS Super Evangelist| MSDN Forums Moderator
ahmedilyas
This is off topic for the Visual C# Language forum, moving to .NET Framework Data Access and Storage forum.


http://www.peterRitchie.com/Blog | MSDN Forums Moderator | Microsoft MVP - Visual Developer, C#
Peter Ritchie

Right the DataReader gets the Values from SQL and thats it... but can u get just the values from the collection of data in the Datset...Like if i use the datareader to get a value how would i get that value if i was using the Dataset is really what i meant....

like this value using a dataset.tables.rows??? Now this is assign the _Date property from the object myCustomerote to dataSet.Tables.Rows[0]["Date"] is that the same thing as giving it just the value but using the dataset instead of the Datareader???



myCustomerNote._Date = (DateTime)ds.Tables[0].Rows[0]["Date"];

 




Give youself a round of applause!!
Tryin2Bgood

not quite sure I follow. Again, the datareader just reads data, and you handle how you want to deal with that data that has been read. the datareader doesn't care about anything else (nor should it) - its a quick fast job "in and out". For advanced features, you would use a DataAdapter, for example, to fill the results into a dataset.

If you mean, you want to add values into a dataset using the DataReader, you could do so however you would be writing alot more code, creating rows, columns, setting the datatype etc... - this is where the DataAdapter comes in handy as it does everything for you pretty much.




Need 2 be back @ MS - MS All the way! Follower since 1995 MS Super Evangelist| MSDN Forums Moderator
ahmedilyas

I see you edited your response whilst I was typing :-)

Well to get the value from a dataset with already populated values, a datareader at this point has nothing to do with anything. in your example, that is the way you would get a value from a dataset/datatable from a specific row and column, and then assign it to a property of your choice.




Need 2 be back @ MS - MS All the way! Follower since 1995 MS Super Evangelist| MSDN Forums Moderator
ahmedilyas
reply 6

You can use google to search for other answers

 

More Articles

• can't insert data into database
• Generating DataSet Relations from XML Schema
• Table Adapter update problems in Strongly Types Dataset
• How to Read Uncommitted Data Created in Same Process?
• GridView in Web Application Not Deleting Rows
• mapping issue with sql executenonquery method
• How to do a programmatic update of table
• Changing the database asociated with a DataSet
• streamreader+inserting/updating the rows in SQL data table
• database search engine class library
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• database MDI application Dataset update
• Saving a Blob file into SQL Server with
• TransactionScope ignores timeout option
• Update without Parameter
• SQLConnection.GetSchema and ForeignKeys
• Read data from an Opened excel file with
• jro.refreshcache on oledbconnection??? (
• Connecting to Access DB
• Interesting behavior causing: "Ther
• ADO.Net Performance
• Update query in DeleteCommand
• How to Pass in a SQL Decimal with Precis
• Internal .Net Framework Data Provider er
• How to Manage Transactions
• delete and update code at the same butto

Hot Articles

• Changes made to multiple tables
• how to create .xml file using SQL query
• DataType Yes/No
• DataSet Vs DataReader????
• Problems deleting a record.
• How to import data from another database
• Error opening a sample .mdf database
• can't insert data into database
• FAQ
• Concurrency Violation on 2 of 3 linked s
• OraclePermission
• Version problem
• parameter Array in Stored Procedure
• Executing query with parameters in VB
• Regional Settings, depending of the form

Recommend Articles

• Returning DataReaders
• [OTP]mouseover and open new page
• ASP.Net worker process can't accessing O
• Simple Update from a VS 2005 vb project
• HOT FIX K921883
• Connection String
• informix: exist a wizard to create datas
• TableAdapter insert/update/delete order
• database MDI application Dataset update
• Excel Query: Can You Query Which Columns
• OleDbCommandBuilder doesn't generate any
• Isolation.ReadUnCommitted Locking Proble
• How can I save textbox with value in the
• How to perform a case insensitive filter
• Please Help ME!!! Web Service about Clie