System.Data.DataSet.Copy C# (CSharp) Method

Copy() public method

Copies both the structure and data for this .
public Copy ( ) : DataSet
return DataSet
        public DataSet Copy()
        {
            long logScopeId = DataCommonEventSource.Log.EnterScope("<ds.DataSet.Copy|API> {0}", ObjectID);
            try
            {
                DataSet dsNew = Clone();
                bool fEnforceConstraints = dsNew.EnforceConstraints;
                dsNew.EnforceConstraints = false;
                foreach (DataTable table in Tables)
                {
                    DataTable destTable = dsNew.Tables[table.TableName, table.Namespace];

                    foreach (DataRow row in table.Rows)
                    {
                        table.CopyRow(destTable, row);
                    }
                }

                dsNew.EnforceConstraints = fEnforceConstraints;

                return dsNew;
            }
            finally
            {
                DataCommonEventSource.Log.ExitScope(logScopeId);
            }
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Add new for case : Convert CPO to new PO
        /// </summary>
        /// <param name="pobjMasterVO"></param>
        /// <param name="pdstDetail"></param>
        /// <param name="pdstDelivery"></param>
        ///<author>TuanDM</author>

        public void UpdatePOAndDelScheduleImmediate(object pobjMasterVO, System.Data.DataSet pdstDetail, DataSet pdstDelivery, ArrayList parlCPOIDs)
        {
            //Add Master and Get returning ID
            PO_PurchaseOrderMasterDS dsPOMaster = new PO_PurchaseOrderMasterDS();

            dsPOMaster.Update(pobjMasterVO);
            var voMaster = (PO_PurchaseOrderMasterVO)pobjMasterVO;

            //Update detail
            DataSet dstPODetail = pdstDetail.Copy();
            PO_PurchaseOrderDetailDS dsPODetail = new PO_PurchaseOrderDetailDS();

            foreach (DataRow drowDetail in pdstDetail.Tables[0].Rows)
            {
                if (drowDetail.RowState == DataRowState.Added)
                {
                    drowDetail[PO_PurchaseOrderDetailTable.PURCHASEORDERMASTERID_FLD] = ((PO_PurchaseOrderMasterVO)pobjMasterVO).PurchaseOrderMasterID;
                }
            }
            dsPODetail.UpdateDataSet(pdstDetail);

            //Get PODetail DataSet which includes PURCHASEORDERDETAILID_FLD
            pdstDetail = dsPODetail.ListToGetID(((PO_PurchaseOrderMasterVO)pobjMasterVO).PurchaseOrderMasterID);

            //Create DeliverySchedule -- and add DeliverySchedule
            int intPOLineID = 0;
            PO_DeliveryScheduleDS dsDelivery = new PO_DeliveryScheduleDS();

            for (int i = 0; i < dstPODetail.Tables[0].Rows.Count; i++)
            {
                DataRow[] drowSameDelivery = pdstDelivery.Tables[0].Select(ITM_ProductTable.PRODUCTID_FLD + "='" + dstPODetail.Tables[0].Rows[i][ITM_ProductTable.PRODUCTID_FLD].ToString() + "'");

                intPOLineID = (int)pdstDetail.Tables[0].Select(PO_PurchaseOrderDetailTable.LINE_FLD + "='" + dstPODetail.Tables[0].Rows[i][PO_PurchaseOrderDetailTable.LINE_FLD].ToString() + "'")[0][PO_PurchaseOrderDetailTable.PURCHASEORDERDETAILID_FLD];
                DataSet dstNewDelPO  = dsDelivery.GetDeliverySchedule(intPOLineID);
                int     intbaseCount = dstNewDelPO.Tables[0].Rows.Count;
                for (int j = 0; j < drowSameDelivery.Length; j++)
                {
                    int k = GetIndexForDeliveryLine(dstNewDelPO, (DateTime)drowSameDelivery[j][PO_DeliveryScheduleTable.SCHEDULEDATE_FLD]);
                    if (k > -1)
                    {
                        dstNewDelPO.Tables[0].Rows[k][PO_DeliveryScheduleTable.DELIVERYQUANTITY_FLD] = (decimal)dstNewDelPO.Tables[0].Rows[k][PO_DeliveryScheduleTable.DELIVERYQUANTITY_FLD] + (decimal)drowSameDelivery[j][PO_DeliveryScheduleTable.DELIVERYQUANTITY_FLD];
                    }
                    else
                    {
                        drowSameDelivery[j][PO_DeliveryScheduleTable.PURCHASEORDERDETAILID_FLD] = intPOLineID;
                        drowSameDelivery[j][PO_DeliveryScheduleTable.DELIVERYLINE_FLD]          = j + 1 + intbaseCount;
                        dstNewDelPO.Tables[0].ImportRow(drowSameDelivery[j]);
                    }
                }
                dsDelivery.UpdateDataSet(dstNewDelPO);
            }

            //Update CPODetail
            MTR_CPODS dsCPO = new MTR_CPODS();

            dsCPO.SetPOMasterID(parlCPOIDs, ((PO_PurchaseOrderMasterVO)pobjMasterVO).PurchaseOrderMasterID);
        }
All Usage Examples Of System.Data.DataSet::Copy