Datareader question

P

Piotrekk

I have a question related to DataReader

Suppose a lot of the data is being retrieved from database. To make
use of the advantage of datareader over dataset this data should be
transferred in HttpResponse to the user that request the site. Is this
possible that the data will display to the user as datareader reads
them from database?

Regards
Piotr Ko³odziej
 
L

Liz

<<
I have a question related to DataReader

Suppose a lot of the data is being retrieved from database. To make
use of the advantage of datareader over dataset this data should be
transferred in HttpResponse to the user that request the site. Is this
possible that the data will display to the user as datareader reads
them from database?

Regards
Piotr Ko³odziej

while (reader.Read())
{
Response.Write( reader[0].ToString());
}

I haven't run that but I should think it would do what you're asking ...
 
P

Peter Bromberg [C# MVP]

You are typically not going to see much difference here because usually the
data is used to bind to some sort of display control first such as a
GridView, Repeater, DataList. The control would have the CSS style
properties, colors and so on to provide a nice display vs. just streaming out
pieces of HTML into the Response stream.

The slight additional overhead of using a DataSet vs. a DataReader gives you
the flexibility to do sorting and filtering, as well as paging.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
 
A

Arne Vajhøj

Piotrekk said:
I have a question related to DataReader

Suppose a lot of the data is being retrieved from database. To make
use of the advantage of datareader over dataset this data should be
transferred in HttpResponse to the user that request the site. Is this
possible that the data will display to the user as datareader reads
them from database?

Are you asking that if you use a data reader and start writing
to response (ASP.NET !) whether the browser will start display
the first data before you have written the last data ?

(I think the answer is no, but you should get an answer from
a more ASP.NET knowledgable person than me)

Arne
 
M

Marc Gravell

For most web pages it is largely academic. As others have noted you
are likely to want to format etc - plus the data volumes on a typical
web page are small enough not to matter.

This might, however, be useful for "handler" implementations, such as
file exports. If you disable buffering you can output to the response
as you have it:

public class MyHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.Buffer = false;
int pause; // can specify the throttle at the query-string
int.TryParse(context.Request["foo"], out pause);
context.Response.ContentType = "text/plain";
context.Response.AddHeader("content-disposition",
"attachment; filename=bar.csv");
TextWriter tw = context.Response.Output;
for (int i = 0; i < 100000; i++)
{
tw.WriteLine(i);
Thread.Sleep(pause); // fake some slowness
}
context.Response.Close();
}

public bool IsReusable{get {return true;}}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top