日期:2014-05-18  浏览次数:20819 次

为什么用.Merge合并查询不成功
一张表只有 car_fee_flag = 1和car_fee_flag = 2两个查询条件不同。现在用.Merge合并两个查询条件,但是现在只能返回一个查询结果。我想要把两个查询结果并列的显示在一个表中(一、二列)
C# code

private void b_lookfor_Click(object sender, EventArgs e)
        {
            string sql_str = "";
            DataTable dt1 = new DataTable();
            DataTable dt2 = new DataTable();
            fee_conn fee_conn = new fee_conn();
            SqlDataAdapter find_do;
            if (DateTime.Compare(d_end, d_start) > 0)
            {
                
                SqlConnection conn = new SqlConnection(fee_conn.sql_conn());
                sql_str = "select * from car_park_fee where car_fee_flag = 1";
                find_do = new SqlDataAdapter(sql_str, conn);
                find_do.Fill(dt1);

                sql_str = "select * from car_park_fee where car_fee_flag = 2";
                find_do = new SqlDataAdapter(sql_str, conn);
                find_do.Fill(dt2);

                dt1.Merge(dt2);
                d_report.Visible = true;
                d_report.DataSource = dt1;
       
                            
             }   
    }



------解决方案--------------------
探讨

LZ试下以下方法

datatable dt=dt1.Merge(dt2,true);
d_report.Visible = true;
d_report.DataSource = dt;

或者

datatable dt=dt1.Merge(dt2);
d_report.Visible = true;
d_report.DataSource = dt;


但是为什……

------解决方案--------------------
探讨

引用:
引用:

这是什么问题呀?
C# code

DataTable dt = dt1.Merge(dt2);
无法将类型“void”隐式转换为“System.Data.DataTable”

dt1.Merge(dt2);Merge无返回值啊,
dt1.Merge(dt2);就这样,合并到了dt……