Public List <VoucherEntryEntity> AnalyseVoucherEntry (DataTable voucherentry)
{
VoucherEntryEntity voucherentryentity = new VoucherEntryEntity ();
List <VoucherEntryEntity> listVoucherEntity = new List <VoucherEntryEntity> ();
For (int I = 0; I <voucherentry. Rows. Count; I ++)
{
Voucherentryentity. FBrNo = voucherentry. Rows [I] ["FBrNo"]. ToString ();
Voucherentryentity. FExplanation = voucherentry. Rows [I] ["FExplanation"]. ToString ();
Voucherentryentity. FAccountID = Convert. ToInt32 (voucherentry. Rows [I] ["FAccountID"]);
Voucherentryentity. FDetailID = Convert. ToInt32 (voucherentry. Rows [I] ["FDetailID"]);
Voucherentryentity. FCurrencyID = Convert. ToInt32 (voucherentry. Rows [I] ["FCurrencyID"]);
Voucherentryentity. FExchangeRate = float. Parse (voucherentry. Rows [I] ["FExchangeRate"]. ToString ());
Voucherentryentity. FDC = Convert. ToInt32 (voucherentry. Rows [I] ["FDC"]);
Voucherentryentity. FAmountFor = Convert. ToDecimal (voucherentry. Rows [I] ["FAmountFor"]);
Voucherentryentity. FAmount = Convert. ToDecimal (voucherentry. Rows [I] ["FAmount"]);
Voucherentryentity. FQuantity = float. Parse (voucherentry. Rows [I] ["FQuantity"]. ToString ());
Voucherentryentity. FMeasureUnitID = Convert. ToInt32 (voucherentry. Rows [I] ["FMeasureUnitID"]);
Voucherentryentity. FUnitPrice = float. Parse (voucherentry. Rows [I] ["FUnitPrice"]. ToString ());
Voucherentryentity. FInternalInd = voucherentry. Rows [I] ["FInternalInd"]. ToString ();
Voucherentryentity. FAccountID2 = Convert. ToInt32 (voucherentry. Rows [I] ["FAccountID2"]);
Voucherentryentity. FSettleTypeID = Convert. ToInt32 (voucherentry. Rows [I] ["FSettleTypeID"]);
Voucherentryentity. FSettleNo = voucherentry. Rows [I] ["FSettleNo"]. ToString ();
Voucherentryentity. FTransNo = voucherentry. Rows [I] ["FTransNo"]. ToString ();
Voucherentryentity. FCashFlowItem = Convert. ToInt32 (voucherentry. Rows [I] ["FCashFlowItem"]);
Voucherentryentity. FTaskID = Convert. ToInt32 (voucherentry. Rows [I] ["FTaskID"]);
Voucherentryentity. FResourceID = Convert. ToInt32 (voucherentry. Rows [I] ["FResourceID"]);
ListVoucherEntity. Add (voucherentryentity );
}
Return listVoucherEntity;
}
When multiple data entries are added, all values are the last result.
It turns out that in. net, a reference is retained each time when list is added, so VoucherEntryEntity voucherentryentity = new VoucherEntryEntity ();
Put it in the for loop to avoid repeated values after adding, that is, every loop, VoucherEntryEntity will be new.
Public List <VoucherEntryEntity> AnalyseVoucherEntry (DataTable voucherentry)
{
List <VoucherEntryEntity> listVoucherEntity = new List <VoucherEntryEntity> ();
For (int I = 0; I <voucherentry. Rows. Count; I ++)
{
VoucherEntryEntity voucherentryentity = new VoucherEntryEntity ();
Voucherentryentity. FBrNo = voucherentry. Rows [I] ["FBrNo"]. ToString ();
Voucherentryentity. FExplanation = voucherentry. Rows [I] ["FExplanation"]. ToString ();
Voucherentryentity. FAccountID = Convert. ToInt32 (voucherentry. Rows [I] ["FAccountID"]);
Voucherentryentity. FDetailID = Convert. ToInt32 (voucherentry. Rows [I] ["FDetailID"]);
Voucherentryentity. FCurrencyID = Convert. ToInt32 (voucherentry. Rows [I] ["FCurrencyID"]);
Voucherentryentity. FExchangeRate = float. Parse (voucherentry. Rows [I] ["FExchangeRate"]. ToString ());
Voucherentryentity. FDC = Convert. ToInt32 (voucherentry. Rows [I] ["FDC"]);
Voucherentryentity. FAmountFor = Convert. ToDecimal (voucherentry. Rows [I] ["FAmountFor"]);
Voucherentryentity. FAmount = Convert. ToDecimal (voucherentry. Rows [I] ["FAmount"]);
Voucherentryentity. FQuantity = float. Parse (voucherentry. Rows [I] ["FQuantity"]. ToString ());
Voucherentryentity. FMeasureUnitID = Convert. ToInt32 (voucherentry. Rows [I] ["FMeasureUnitID"]);
Voucherentryentity. FUnitPrice = float. Parse (voucherentry. Rows [I] ["FUnitPrice"]. ToString ());
Voucherentryentity. FInternalInd = voucherentry. Rows [I] ["FInternalInd"]. ToString ();
Voucherentryentity. FAccountID2 = Convert. ToInt32 (voucherentry. Rows [I] ["FAccountID2"]);
Voucherentryentity. FSettleTypeID = Convert. ToInt32 (voucherentry. Rows [I] ["FSettleTypeID"]);
Voucherentryentity. FSettleNo = voucherentry. Rows [I] ["FSettleNo"]. ToString ();
Voucherentryentity. FTransNo = voucherentry. Rows [I] ["FTransNo"]. ToString ();
Voucherentryentity. FCashFlowItem = Convert. ToInt32 (voucherentry. Rows [I] ["FCashFlowItem"]);
Voucherentryentity. FTaskID = Convert. ToInt32 (voucherentry. Rows [I] ["FTaskID"]);
Voucherentryentity. FResourceID = Convert. ToInt32 (voucherentry. Rows [I] ["FResourceID"]);
ListVoucherEntity. Add (voucherentryentity );
}
Return listVoucherEntity;
}