开发者

SqlDataReader return rows

If we select a large number of rows and use an SqlDataReader, will开发者_如何学Go it return the rows as they come or will it wait until the operation is complete?

This is with C#.net


It'll return the rows as they come. Each time you call SqlDataReader.Read(); the next row is retrieved from the client's network buffer. Only one row is held in memory on each Read().

// Starts getting the data from the query 
IDataReader reader = cmd.ExecuteReader(behavior); 

// Calling .Read() will get the next result from the client network buffer
while (reader.Read())
{
   // Do something with the row data
}

More information here.


They are streamed. If you review the "remarks" section it states that certain properties can only be safely read once the reader closes. If the complete result set was known prior to starting, these properties would be safe to read while the reader was open.

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜