4 在DATASET中要是想添加进另一个表怎么办?
问:
sql="select * from banzhu_manage ";
adapter=new SqlDataAdapter(sql,banzhu_conn);
adapter.Fill(banzhu_ds,"banzhu_manage");
上面是我在爱适配器,中对DATASET进行填充,
要是我想在DATASET中添加另一个数据库中已经存在的表该怎么做?
______________________________________________________________________________________________
答1:
还用这个:
sql="select * from annothertabel ";
adapter=new SqlDataAdapter(sql,banzhu_conn);
adapter.Fill(banzhu_ds,"tablename");
______________________________________________________________________________________________
答2:
DataSet 里边是Table 的集合,可以对一个DataSet填充多个Table,前提是给每个Table起名不同,然后可以根据Table的名称来调用它。
如
//填充
sda1.Fill(ds,"table1");
sda2.Fill(ds,"table2");
...
sdaN.Fill(ds,"tableN");
//取
DataGrid1.DataSource = ds.Tables["table1"].DefaultView;
DataGrid2.DataSource = ds.Tables["table2"].DefaultView;
...
DataGridN.DataSource = ds.Tables["tableN"].DefaultView;
______________________________________________________________________________________________
答3:
楼上说得很清楚
______________________________________________________________________________________________
答4:
sql="select * from banzhu_manage ";
adapter=new SqlDataAdapter(sql,banzhu_conn);
adapter.Fill(banzhu_ds,"banzhu_manage");
上面是我在爱适配器,中对DATASET进行填充,
要是我想在DATASET中添加另一个数据库中已经存在的表该怎么做?
//==>
sql="select * from banzhu_manage; select * from table2 ";
adapter=new SqlDataAdapter(sql,banzhu_conn);
adapter.Fill(ds)
就有
ds.Tables[0]
ds.Tables[1]
______________________________________________________________________________________________
答5:
就是用适配器再添加呀。
sql="select * from 表名 ";
adapter=new SqlDataAdapter(sql,banzhu_conn);
adapter.Fill(banzhu_ds,"表名");
。。。
sql="select * from 表名1 ";
adapter=new SqlDataAdapter(sql,banzhu_conn);
adapter.Fill(banzhu_ds,"表名1");
然后dataset中就有你添加的几个表了,若是你要选择哪个表的话,你就用ds.Tables[0]或者ds.Tables[“表名”]。