仅在LIST中获取当前数据 [英] Getting current data only in LIST

查看:75
本文介绍了仅在LIST中获取当前数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个列表,我填写不同的记录(比如说25),但只收到所有25条记录相同的数据。



Hi,

I have list where I am filling it with different records(say 25) but getting in all 25 records same data only.

for (var invoiceRow = 0; invoiceRow < dataTableInvoice.Rows.Count; invoiceRow++)
{
    invoiceEntity.Rowno = Convert.ToInt32(dataTableInvoice.Rows[invoiceRow]["Rowno"]);
    invoiceEntity.ProjectName = Convert.ToString(dataTableInvoice.Rows[invoiceRow]["ProjectName"]);
    invoiceEntity.EmployeeRoleTypeName = Convert.ToString(dataTableInvoice.Rows[invoiceRow]["EmployeeRoleTypeName"]);
    invoiceEntity.WorkHours = Convert.ToInt32(dataTableInvoice.Rows[invoiceRow]["WorkHours"]);
 
    if (invoiceEntity.Rowno == -1)
    {
        invoiceEntity.InvoiceStartNo = "";
        invoicestartupno--;
    }
   
    var invoiceNumberFormat = invoicestartupno.ToString("D4");
    invoiceEntity.InvoiceStartNo = String.Format("{0}-{1}", invoiceno, invoiceNumberFormat);
    dataTableInvoice.Rows[invoiceRow]["InvoiceStartNo"] = invoiceEntity.InvoiceStartNo;
    invoiceEntity.CurrentDate = (dataTableInvoice.Rows[invoiceRow]["CurrentDate"]) == DBNull.Value 
        ? (DateTime?)null 
        : Convert.ToDateTime(dataTableInvoice.Rows[invoiceRow]["CurrentDate"]
    );
    invoiceEntity.TotalWorkingDays = workingDays;
    invoiceEntity.TotalWorkingHrs = workingHrs;
    invoiceEntity.BillableHrs = billableHrs;
    invoiceEntity.NonBillableHrs = nonBillableHrs;
    invoiceEntity.DateRange = dateSeries;

    invoicestartupno++;

    invoiceList.Add(invoiceEntity);
}





使用invoiceList获取每条记录中的相同数据



如何解决这个问题



帮助将会很明显



when using invoiceList getting same data in each record

how can I resolve this

help will be appreciable

推荐答案

你正在添加同样 invoiceEntity 一次又一次......这可能是你的错误...或故意这个?



如果不,你应该做
You're adding the same invoiceEntity again and again... this could be your bug... or this intentionally?

If not, you should do
var invoiceEntity = new [WHATEVER YOUR TYPE IS]();

然后设置数据......

and set the data afterwards...


这篇关于仅在LIST中获取当前数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆