我先有2个表查出2个datatable如下
字段意思分别是
------ 日期 收入项目 现金  刷卡  流水号 门店 备注 操作员 string sql1 = "select c.cDate,c.cItem,c.cAmountCash,c.cAmountCredit,c.cNo,O.oName,c.cRe,e.eName from Consume c,Outlet o,Employee e where o.oNumber=c.cOutlet and c.cCashier=e.eNumber";
DataTable dt1 = BaseAccess.GetDataTable(sql1);string sql2 = "select p.pDate,'会员卡充值' 'pItem',p.pAmountCash,p.pAmountCredit,p.pNo,O.oName,p.pRe,e.eName from PrepaidRecords p,Outlet o,Employee e where o.oNumber=p.pOutlet and p.cCashier=e.eNumber";
DataTable dt2 = BaseAccess.GetDataTable(sql2);
请问如何操作 ,谢谢了

解决方案 »

  1.   

    循环赋值到同一个datatable中,或者用一个dataset接收两个sql查询的结果,然后用dataset绑定gv
      

  2.   

    如果兩個表結構一樣的話可以使用
    DataTable Dt1=new DataTable();
    DataTable Dt2=new DataTable();
    Dt1.Merge(Dt2);
    Dt1 is what you want
      

  3.   

    这样是把2个datat接起来了  我试过 
    我要把数据合并了 一起显示 不是多搞出几列
      

  4.   

    列数相同 尽量在sql 上去想办法。用union allstring sql1 = "select c.cDate,c.cItem,c.cAmountCash,c.cAmountCredit,c.cNo,O.oName,c.cRe,e.eName from Consume c,Outlet o,Employee e where o.oNumber=c.cOutlet and c.cCashier=e.eNumber
    union all 
    select p.pDate,'会员卡充值' 'pItem',p.pAmountCash,p.pAmountCredit,p.pNo,O.oName,p.pRe,e.eName from PrepaidRecords p,Outlet o,Employee e where o.oNumber=p.pOutlet and p.cCashier=e.eNumber
    ";
      

  5.   

    顶楼上的、用union all就好了、针对结构一样的表。
      

  6.   


    我咋这么死脑筋呢
    就往datatable上想
    为什么不在sql想办法呢 哎 
    继续等待 看还有没有好的方法
      

  7.   


    int count=dt1.Rows.Count;
    for(int i=0;i<count;i++)
    {
       DataRow row=dt2.NewRow();
       row[0]=dt1.Rows[i][0];
       row[1]=dt1.Rows[i][1];
       //……
       dt2.Rows.Add(row);
    }或者在查询的时候,用union all将结果查到一个dt中
      

  8.   

    先构造一个空的DataTable然后把需要的数据添加进去啊。
    也可以在原有的DataTable里添加列 在加入第二个表的数据
      

  9.   


    效率低太低,做一个压力测试就down了
    最好的办法就是在数据库两条sql语句
    union一下
    sql1
    union
    sql2
    字段对应就行了
      

  10.   

    采用 left join或right join
      

  11.   

    把两个表里的数据添加到ArrayList里去 。