Advantage of data Reader?

Answer Posted / o p yadav

To highlight the advantages of using a DataReader over the
DataSet, hereā€™s an example of using a DataSet. The following
fills a DataSet with the results from a table, and outputs
the first field in each row:

Code=

SqlConnection conn = new SqlConnection(connectionString);
SqlDataAdapter a = new SqlDataAdapter
("select * from mytable;",conn);
DataSet s = new DataSet();
a.Fill(s);
foreach (DataRow dr in s.Tables[0].Rows)
{
Console.WriteLine(dr[0].ToString());
}

As you can see, we donā€™t actually start the actual
inspection of data (the foreach loop), until the whole
DataSet has been filled. There may be occasions where we may
not use all our results, or we might execute other code
while inspecting (a progress barā€™s progress is a trivial
example). Using a DataSet, this can only take place after
the complete results are fetched and passed into the various
collections within the DataSet.

Is This Answer Correct ?    3 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the difference between function and stored procedure in .net programming language?

262


What is owin authentication?

522


In Data grid the question is below quantity price total these are 3 fields available in data grid if you enter quantity the total has to update automatically.Price field is already filled completely

1551


What is ascx?

539


Do cookies store passwords?

507






What is state management react?

515


How to disable cut, copy and paste in TextBox using jQuery in asp.net?

638


Explain security types in asp.net?

547


What is difference between mvc and asp.net? : Asp.Net MVC

575


What are the ways to show data grid inside a data grid for a master details type of tables? If we write any code for DataGrid methods, what is the access specifier used for that methods in the code behind file and why?

592


What is state management technique?

549


What is the difference between the response.write() and response.output.write() methods?

520


How is session id generated?

458


What are the new features added from ASP to ASP.NET?

573


Which platform does Microsoft .NET use for exchanging data between applications?

589