Remove duplicate data on the basis of a large DataTable, create two small DataTable respectively, save multiple database connections, improve efficiency, speed up program running, datatable updates Database

Source: Internet
Author: User

Remove duplicate data on the basis of a large DataTable, create two small DataTable respectively, save multiple database connections, improve efficiency, speed up program running, datatable updates Database

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 str_Inv_Num Based on orderTable

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 with more than two documents, and each document has repeated records when multiple items are sold. At present, the first item of the First Order Number will list the item information. If there are multiple items in a list, duplicate data will appear if this sentence is not added. The result is 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); // return the generic List
// OracleAccess. logger. Debug ("CAL_getOfflineOrder sub-table:" + str_vip.ToString () + DateTime. Now. ToLongDateString () + DateTime. Now. ToLongTimeString () +
// "," + Str_INV_DATE + "," + str_MemberCode + "," + str_Inv_Num + "," + Inv_Totalamt + "," + str_INV_AMT + "," + int_Sell_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 Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.