Eliminate duplicate data based on a large DataTable, create 2 small DataTable, save multiple database connections, improve efficiency, and speed up program operation

Source: Internet
Author: User

DataTable tab = new DataTable ();

tab = Dbutil.getdataset (Strcmd, "TESTA. V_yhj_vip_wx_xsmx "). Tables[0];

Create a small table:

DataView view = new DataView (tab);


DataTable ordertable = view. ToTable (True, "ORDERDATE", "Member_code", "Inv_num", "Zje", "Zfje", "Sell_qty", "Shop_code");

Generate a smaller table in ordertable-based Str_inv_num

for (int i = 0; i < OrderTable.Rows.Count; i++)
{
for (int j = 0; J < OrderTable.Columns.Count; J + +)
{
if (j = = 0)
{
Str_inv_date = Ordertable.rows[i][j]. ToString (). Trim ();
Shop_code = tab. ROWS[I][J]. ToString ();
}
if (j = = 1)
Str_membercode = Ordertable.rows[i][j]. ToString (). Trim ();
if (j = = 2)
{
Str_inv_num = Ordertable.rows[i][j]. ToString (). Trim ();
Subinv_num = Str_inv_num;
}
if (j = = 3)
Inv_totalamt = Convert.ToInt32 (Ordertable.rows[i][j]. ToString (). Trim ());
if (j = = 4)
Str_inv_amt = Convert.ToInt32 (Ordertable.rows[i][j]. ToString (). Trim ());
if (j = = 5)
Int_sell_qty = Convert.ToInt32 (Ordertable.rows[i][j]. ToString (). Trim ());
if (j = = 6)
Str_shop_code = tab. ROWS[I][J]. ToString (). Trim ();
}


if (Str_old_inv_num.trim ()!=str_inv_num.trim ())//Remove a member who has more than 2 documents, and each document has multiple items for sale in duplicate records. At present, the first item of the first ticket will be listed in the goods, if a list has more than one item, there will be duplicate data without this sentence. Cause the result to be incorrect.
{
View. RowFilter = "inv_num=" + str_inv_num+ "'";
orderdetailtable = view. ToTable (True, "Inv_num", "SKU", "C_short_de", "Sell_qty", "serial_no");


list<cofflineorderdetail> Lcofflineorderdetail = dbutil.getlist<cofflineorderdetail> (orderDetailTable );//Returns a generic list
OracleAccess.logger.Debug ("Cal_getofflineorder table:" + STR_VIP. ToString () + DateTime.Now.ToLongDateString () + DateTime.Now.ToLongTimeString () +
"," + Str_inv_date + "," + Str_membercode + "," + Str_inv_num + "," + Inv_totalamt + "," + Str_inv_amt + "," + int_s Ell_qty + "," + Str_shop_code +
Dbutil.tojson (Subtab));
Listorder. ADD (New Cofflineorder (Str_inv_date, Str_membercode, Str_inv_num, Inv_totalamt, Str_inv_amt, Str_shop_code, Int_Sell_ Qty, Lcofflineorderdetail));
View. RowFilter = "";
Str_old_inv_num = Str_inv_num;
}


}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Eliminate duplicate data on a large DataTable, create 2 small DataTable, save multiple database connections, increase efficiency, and speed up program operation

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.