Extracting Multiple Resultsets from a DataReader
2006-10-13 18:01
399 查看
// read the first resultset reader = command.ExecuteReader(); // read the data from that resultset while (reader.Read()) { suppliers.Add(PopulateSupplierFromIDataReader( reader )); } // read the next resultset reader.NextResult(); // read the data from that second resultset while (reader.Read()) { products.Add(PopulateProductFromIDataReader( reader )); }
Figure 2 Paging Through the Orders Table
CREATE PROCEDURE northwind_OrdersPaged ( @PageIndex int, @PageSize int ) AS BEGIN DECLARE @PageLowerBound int DECLARE @PageUpperBound int DECLARE @RowsToReturn int -- First set the rowcount SET @RowsToReturn = @PageSize * (@PageIndex + 1) SET ROWCOUNT @RowsToReturn -- Set the page bounds SET @PageLowerBound = @PageSize * @PageIndex SET @PageUpperBound = @PageLowerBound + @PageSize + 1 -- Create a temp table to store the select results CREATE TABLE #PageIndex ( IndexId int IDENTITY (1, 1) NOT NULL, OrderID int ) -- Insert into the temp table INSERT INTO #PageIndex (OrderID) SELECT OrderID FROM Orders ORDER BY OrderID DESC -- Return total count SELECT COUNT(OrderID) FROM Orders -- Return paged results SELECT O.* FROM Orders O, #PageIndex PageIndex WHERE O.OrderID = PageIndex.OrderID AND PageIndex.IndexID > @PageLowerBound AND PageIndex.IndexID < @PageUpperBound ORDER BY PageIndex.IndexID END
相关文章推荐
- 关于MultipleActiveResultSets属性导致的There is already an open DataReader associated with this Command which must be closed first的解决方法
- couldn't get cmd pointer (substituting NULL): extracting data from value failed Couldn't materialize
- Extracting Structured Data from Web Pages
- Manual JSON serialization from DataReader in ASP.NET Web API
- Detaching a datastore or storage device from multiple ESXi 5.0 hosts
- Extracting Table Data from Word Document using Aspose Words
- kibi - join and filter data from multiple Elasticsearch indexes
- Python.Extracting Data from JSON
- Display data from multiple sources in a single Data View(转office.Microsoft)
- Extracting Data from array of hashes Ruby
- [文章摘要]Extracting semantics of individual places from movement data by analyzing temporal patterns of
- Python.Extracting Data from XML
- Trick: 巧用.NET Reflection从SqlConnection回溯到打开着的SqlDataReader。(Find the live SqlDataReader from SqlConnection)
- How to bind a GridView to a list of multiple types? NHibernate proxy causing problems with databinding [From stack overflow]
- templatemaker - Python library for extracting data from similarly formatted text strings. - Google Project Hosting
- Extracting Datafile Blocks From ASM
- couldn't get cmd pointer (substituting NULL): extracting data from value failed Couldn't materialize
- Chapter 06-Displaying Data From multiple Tables - 01
- Spark Streaming polling data from Flume
- Sample: Write And Read data from HDFS with java API