Detailed usage of datatable

Source: Internet
Author: User
 
 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 ());
 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.