1 Datatable table = New Datatable (); // Create a new table
2 Datacolumn colid = New Datacolumn ( " ID " , System. type. GetType ( " System. int32 " )); // ID
3 Datacolumn colname = New Datacolumn ( " Name " , System. type. GetType ( " System. String " )); // Name
4 Datacolumn colnum = New Datacolumn ( " Num " , System. type. GetType ( " System. int32 " )); // Quantity
5 Datacolumn colprice = New Datacolumn ( " Price " , System. type. GetType (" System. Double " )); // Purchase Price
6 Datacolumn colplace = New Datacolumn ( " Place " , System. type. GetType ( " System. String " )); // Supplier
7 Datacolumn coldescription = New Datacolumn ( " Description " , System. type. GetType ( " System. String " )); // Remarks
8 Table. primarykey =New Datacolumn [] {table. Columns [ " ID " ]};
9 // Add all the define Column
10 Table. Columns. addrange ( New Datacolumn [] {colid, colname, colnum, colplace, colprice, coldescription });
11
12 // Add a line of data
13 Datarow ROW = table. newrow ();
14 Row [colid] = 1 ;
15 Row [colname] = " ThinkPad-E420 " ;
16 Row [colnum] = 10 ;
17 Row [colprice] = 4000 ;
18 Row [colplace] = " Nanjing suchong " ;
19 Row [coldescription] = " Test Data " ;
20 Table. Rows. Add (ROW );
21
22 // Query
23 Datarow [] searchrows = table. Select ();
24 Datarow [] searchrows1 = table. Select ( " Id = 1 " );
25 // Value
26 Console. writeline (searchrows [ 0 ] [ 0 ]. Tostring ());