如何合并数据视图值

发布于 2025-01-03 12:16:25 字数 1421 浏览 0 评论 0原文

我想将相同的数据视图值合并到另一个数据视图..

我的代码在这里:

for (int i = 0; i < lbxempname.Items.Count; i++)
{
    if (lbxempname.Items[i].Selected)
    {
        string id = lbxempname.Items[i].Text;
        string substr = id.Substring(0, 8);
        string Expression = "Employee_ID='" + substr + "' and Punchdate >=#" + txtstartdate.Text + "# and Punchdate <=#" + txtenddate.Text + "#";
        DataSet4TableAdapters.sp_getalltimesheetTableAdapter TA1 = new DataSet4TableAdapters.sp_getalltimesheetTableAdapter();
        DataSet4.sp_getalltimesheetDataTable DS1 = TA1.GetData();
        datavw = DS1.DefaultView;
        datavw.RowFilter = Expression;
    }
    newdatavw = new DataView ();
    newdatavw.Table.Merge(datavw.Table);
}

第一个循环,数据视图有一些像这样的记录...

   EmployeeId   EmployeeName    Department  Date            Day     Intime      Outtime     Late_After  Early_Before    Remarks
   00626243         HariharanJ  SBS IT      01-04-2012  Wednesday   06:40:00    15:00:00    00:00        00:00          P
   00626243         HariharanJ  SBS IT      01-03-2012  Tuesday     00:00:00    14:40:00    00:00        00:05          P
   00626243         HariharanJ  SBS IT      01-05-2012  Thursday    07:00:00    14:35:00    00:20        00:10          P

第二个也有一些具有相同标题的记录.. 但我想将两条记录导出到一个 Excel 中,并为每条记录添加标题和单个制动器。请我创建它时遇到麻烦。我可以将单个记录导出到 Excel,但我无法导出所有记录...

I want to merge same dataview value to another dataview ..

My code is here:

for (int i = 0; i < lbxempname.Items.Count; i++)
{
    if (lbxempname.Items[i].Selected)
    {
        string id = lbxempname.Items[i].Text;
        string substr = id.Substring(0, 8);
        string Expression = "Employee_ID='" + substr + "' and Punchdate >=#" + txtstartdate.Text + "# and Punchdate <=#" + txtenddate.Text + "#";
        DataSet4TableAdapters.sp_getalltimesheetTableAdapter TA1 = new DataSet4TableAdapters.sp_getalltimesheetTableAdapter();
        DataSet4.sp_getalltimesheetDataTable DS1 = TA1.GetData();
        datavw = DS1.DefaultView;
        datavw.RowFilter = Expression;
    }
    newdatavw = new DataView ();
    newdatavw.Table.Merge(datavw.Table);
}

First looping, dataview have some records like this...

   EmployeeId   EmployeeName    Department  Date            Day     Intime      Outtime     Late_After  Early_Before    Remarks
   00626243         HariharanJ  SBS IT      01-04-2012  Wednesday   06:40:00    15:00:00    00:00        00:00          P
   00626243         HariharanJ  SBS IT      01-03-2012  Tuesday     00:00:00    14:40:00    00:00        00:05          P
   00626243         HariharanJ  SBS IT      01-05-2012  Thursday    07:00:00    14:35:00    00:20        00:10          P

and second also having some records with same header..
But i want to Export both records in a single Excel with header and a single brake for each record. Please i was trouble to create it.I can Export a single record to excel but i can't export all record...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我闹别瞎闹 2025-01-10 12:16:25
newdatavw.Table.Merge(datavw.Table);

更改上面的代码:

newdatavw.Table.Merge(datavw.ToTable());

DataView.ToTable(); ==>使用 DataView 返回一个新的 DataTable

newdatavw.Table.Merge(datavw.Table);

change your Code above:

newdatavw.Table.Merge(datavw.ToTable());

DataView.ToTable(); ==>Return a new DataTable with DataView

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文