Creating an ADO.NET Shopping Cart • Chapter 12 |
549 |
public DataSet catalogByCategory( int catId)
protected DataSet catalogRangeByCategory(
int startPos, int range, int catId, string book_isbn)
}
Creating the CreateSummaryTable Method
The CreateSummaryTable method creates a DataTable that contains summary information about the DataSet being returned.This data is used by the XSLT to display Metadata (i.e., viewing records 6 through 12 of 25). It is also useful when making a fetch next range of records call.
Based on the prototype, this method will take the parameters int startPos, int range, and int RecordCount and will return a DataTable. Let’s get started.
1. Create a new empty DataTable named “summary”.
DataTable dtSummary = new DataTable("Summary");
In the XSD schema this makes the DataTables parent
element a summary tag (i.e. <summary> )
2.Now add the Columns RecordCount, FirstItemIndex, and LastItemIndex to the Summary DataTable.
dtSummary.Columns.Add(
new DataColumn("RecordCount", typeof(int)));
dtSummary.Columns.Add(
new DataColumn("FirstItemIndex", typeof(int)));
dtSummary.Columns.Add(
new DataColumn("LastItemIndex", typeof(int)));
3. Create a new DataRow object and assign it to a new DataTable row.
DataRow drSummary;
drSummary = dtSummary.NewRow();
4. Populate the DataRow object and add it to the DataTable.
drSummary["RecordCount"] |
= RecordCount; |
drSummary["FirstItemIndex"] = startPos;
drSummary["LastItemIndex"] = startPos + range;
dtSummary.Rows.Add( drSummary );