如何合并dataview值

时间:2012-02-07 05:44:36

标签: c# asp.net dataview

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

我的代码在这里:

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

首先循环,dataview有一些像这样的记录......

   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中导出两个记录,每个记录都有标题和一个制动器。请我创建它很麻烦。我可以将单个记录导出为ex​​cel但我无法导出所有记录...

1 个答案:

答案 0 :(得分:0)

newdatavw.Table.Merge(datavw.Table);

更改上面的代码:

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

DataView.ToTable(); ==&gt;使用DataView

返回新的DataTable