Basic usage of DataTable day1

Source: Internet
Author: User

DataTable dtprobaselist = new DataTable ("Dtprobaselist");
DTPROBASELIST.COLUMNS.ADD ("Id", Type.GetType ("System.String"));
DTPROBASELIST.COLUMNS.ADD ("ProductId", Type.GetType ("System.String"));
DTPROBASELIST.COLUMNS.ADD ("Cname", Type.GetType ("System.String"));
DTPROBASELIST.COLUMNS.ADD ("Barcode", Type.GetType ("System.String"));

DataTable dtexams = new DataTable ("Dtexams");

DTEXAMS.COLUMNS.ADD ("Id", Type.GetType ("System.String"));
DTEXAMS.COLUMNS.ADD ("Flowproid", Type.GetType ("System.String"));
DTEXAMS.COLUMNS.ADD ("ProductId", Type.GetType ("System.String"));
DTEXAMS.COLUMNS.ADD ("Cname", Type.GetType ("System.String"));

DataColumn KeyColumn = dtprobaselist.columns["Id"];//get primary key

Keycolumn.unique = true;

Keycolumn.allowdbnull=false;

Keycolumn.autoincrement = true;//Auto-Grow
Keycolumn.autoincrementseed = 0;//Start value
Keycolumn.autoincrementstep = 1;//Increment

DataColumn foreignkeycolumn = dtexams.columns["flowproid"];//foreign key

DataSet ds=new DataSet ();

Ds. Tables.add (dtprobaselist);//Add Table
Ds. Tables.add (Dtexams);

Ds. Relations.Add ("Productexam", KeyColumn, Foreignkeycolumn);//Building relationships

Calculate statistics

//
Summary:
Calculates the given expression on the current line that is used to pass the filter condition.
//
Parameters:
Expression
The expression to evaluate.
//
Filter
The filter to limit the rows that are evaluated in an expression.
//
return Result:
System.Object, set to the calculated result.
public object Compute (string expression, string filter);

1. Sum of one column

Eg summation: sel=1 and payment_type= ' 2 ' and

Decimal. TryParse (dsproductlist.tables["Nopay"). Compute ("sum (AMOUNT)", "sel= ' 1 ' and payment_type= ' 2 '"). ToString (), out selfpay);

2. Totals for multiple columns

DataRow Drarr[]=null;

Drarr.sum (p = p.field<decimal> ("Discountprice") * p.field<int32> ("Count"))

Basic usage of DataTable day1

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.