private void UpdateMobileSalesOrder() { SqlCompactConnection conn = new SqlCompactConnection(); try { conn.connect(); DataTable dt = new DataTable(); string sql = "select salesorderid,salespersonid from salesorderheader where status <> 1"; dt = conn.GetDataTable(sql); int rows = dt.Rows.Count; int i = 0; progressBar1.Minimum = 0; progressBar1.Maximum = rows; foreach (DataRow dr in dt.Rows) { //Get sales order data from server. SalesOrderHeader soh = new SalesOrderHeader(); SalesOrderHeaderCollection SohCol = new SalesOrderHeaderCollection(); string where = "CurrencyRateID=" + dr["SalesOrderID"].ToString(); where += " and SalesPersonID=" + dr["SalesPersonID"].ToString(); string orderby = "SalesOrderID"; SohCol = soh.GetSalesOrderHeaderCollection(where, orderby); int count = SohCol.Count; if (count == 0) { continue; } //update salesorder in mobile. SohCol[0].Status = 9; soh.UpdateSalesOrderHeaderMobile(SohCol[0]); //get server order details SalesOrderDetail sod = new SalesOrderDetail(); SalesOrderDetailCollection SodCol = new SalesOrderDetailCollection(); where = "SalesOrderID=" + SohCol[0].SalesOrderID; orderby = "SalesOrderID"; SodCol = sod.GetSalesOrderDetailCollection(where, orderby); //Delete sales order details from mobile sod.DeleteSalesOrderDetailMobile(SohCol[0].CurrencyRateID); //copy sales order details from the server to the mobile. for (int j = 0; j < SodCol.Count; j++) { SodCol[j].SalesOrderID = SohCol[0].CurrencyRateID; sod.AddSalesOrderDetailsMobile(SodCol[j]); } i++; progressBar1.Value = i; RefreshForm(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "MICS", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { conn.CloseDatabase(); conn = null; } }