Most of my post on retrieving my Product list focused on the Stored Procedure. When it came time to implement the same list with a TableAdapter all that work was already done for me. My steps became:
- New dataset.
- Drag my stored procedure from server explorer.
- Rename the table and tableadapter
- And there we have it:
I then double clicked on the designer and edited the codebehind file to allow my DataRows to implement my IProduct interface:
1 using System;
2 using BrowniesBikes.DTO;
3
4 namespace BrowniesBikes.Data.TableAdapter {
5
6
7 partial class ProductDS
8 {
9 partial class ProductListRow : IProduct
10 {
11 #region IProduct Members
12
13 public int? PhotoID
14 {
15 get { throw new System.NotImplementedException(); }
16 set { throw new System.NotImplementedException(); }
17 }
18
19 ...etc...
20 #endregion
21 }
22 }
23 }
My DAL class ended up with very little code:
18 public IEnumerable<IProduct> GetProductList(
19 string searchString,
20 string sortExpression,
21 int startRow,
22 int maxRows)
23 {
24 int endRow = startRow + maxRows;
25 ProductListTableAdapter productListTableAdapter =
26 new ProductListTableAdapter();
27
28 int? totalProducts = 0;
29
30 ProductDS.ProductListDataTable listDataTable =
31 productListTableAdapter.GetData(
32 searchString,
33 startRow,
34 endRow,
35 sortExpression,
36 ref totalProducts);
37
38 foreach (ProductDS.ProductListRow row in
39 listDataTable.Rows)
40 {
41 yield return row;
42 }
43 }
Deceptively easy. Keep an eye out for my post on inserting and updating as well as TableAdapter maintenance. There are some major pain points coming your way.
Print | posted on Saturday, January 05, 2008 8:19 PM