手工建表的步骤
1<%
2DataTable dtblCart;
3DataRow drowItem;
4// Display DataTable
5
6// Create DataTable
7dtblCart = new DataTable( "Cart" );
8
9// Create Columns
10DataColumn dcolColumn = new DataColumn( "ProductID", typeof( Int32 ) );
11dtblCart.Columns.Add( dcolColumn );
12dcolColumn = new DataColumn( "ProductName", typeof( string ) );
13dtblCart.Columns.Add( dcolColumn );
14dcolColumn = new DataColumn( "ProductCategory", typeof( string ) );
15dtblCart.Columns.Add( dcolColumn );
16dcolColumn = new DataColumn( "ProductPrice", typeof( Decimal ) );
17dtblCart.Columns.Add( dcolColumn );
18
19// Add Rows
20drowItem = dtblCart.NewRow();
21drowItem[ "ProductID" ] = 12;
22drowItem[ "ProductName" ] = "Anchor Steam";
23drowItem[ "ProductCategory" ] = "Beer";
24drowItem[ "ProductPrice" ] = 7.90;
25dtblCart.Rows.Add( drowItem );
26 //Add Rows
27drowItem = dtblCart.NewRow();
28drowItem[ "ProductID" ] = 13;
29drowItem[ "ProductName" ] = "Samuel Adams";
30drowItem[ "ProductCategory" ] = "Beer";
31drowItem[ "ProductPrice" ] = 8.67;
32dtblCart.Rows.Add( drowItem );
33foreach (DataRow row in dtblCart.Rows)
34{
35 foreach (DataColumn column in dtblCart.Columns)
36 {
37 Response.Write( row[ column ]);
38 }
39}
40
41%>
42
2DataTable dtblCart;
3DataRow drowItem;
4// Display DataTable
5
6// Create DataTable
7dtblCart = new DataTable( "Cart" );
8
9// Create Columns
10DataColumn dcolColumn = new DataColumn( "ProductID", typeof( Int32 ) );
11dtblCart.Columns.Add( dcolColumn );
12dcolColumn = new DataColumn( "ProductName", typeof( string ) );
13dtblCart.Columns.Add( dcolColumn );
14dcolColumn = new DataColumn( "ProductCategory", typeof( string ) );
15dtblCart.Columns.Add( dcolColumn );
16dcolColumn = new DataColumn( "ProductPrice", typeof( Decimal ) );
17dtblCart.Columns.Add( dcolColumn );
18
19// Add Rows
20drowItem = dtblCart.NewRow();
21drowItem[ "ProductID" ] = 12;
22drowItem[ "ProductName" ] = "Anchor Steam";
23drowItem[ "ProductCategory" ] = "Beer";
24drowItem[ "ProductPrice" ] = 7.90;
25dtblCart.Rows.Add( drowItem );
26 //Add Rows
27drowItem = dtblCart.NewRow();
28drowItem[ "ProductID" ] = 13;
29drowItem[ "ProductName" ] = "Samuel Adams";
30drowItem[ "ProductCategory" ] = "Beer";
31drowItem[ "ProductPrice" ] = 8.67;
32dtblCart.Rows.Add( drowItem );
33foreach (DataRow row in dtblCart.Rows)
34{
35 foreach (DataColumn column in dtblCart.Columns)
36 {
37 Response.Write( row[ column ]);
38 }
39}
40
41%>
42