请教一个关于DataSet合并两张表的问题
如题:我现在想把查询出来的数据放在个表中,我在网上看到可以通过DataSet.Merge(DataSet)这种方法来合并,但是我试了一下,只能显示出第一个DataSet里存的表的数据,请问这是什么原因?代码如下:
string models= " ";
reader = dc.GetReader( "select models from products_Info where pro_id = 1 ");
if(reader.Read())
{
models = reader.GetValue(0).ToString();
reader.Close();
}
DataSet ds = new DataSet();
string sql= "select storesname,tel from customer where [id] in (select customer_id from products_Info where models = ' "+models+ " ') ";
adapter = new SqlDataAdapter(sql,cn);
adapter.Fill(ds, "customer ");
DataSet dsl =new DataSet();
string sqlprice = "select price from products_Info where models = ' "+models+ " ' ";
SqlDataAdapter adap = new SqlDataAdapter(sqlprice,cn);
adapter.Fill(dsl, "products_Info ");
ds.Merge(dsl.Tables[0]);
DataGrid1.DataSource= dt3;
DataGrid1.DataBind();
------解决方案--------------------
因为你的dt3是空的,这样直接使用其他DataTable的行来填充一个新的dt是不允许的,你可以通过创建新的DataRow 来填充你的DataTable