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.