After List generic Add, all values are the solution to the last Add result.

Source: Internet
Author: User

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;
}

 

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.