表db_list id 服务器名(TableName) 井名字(WellId) 时间 (InsertTime) 1 [WIS00001] B1ST4 2011-12-01 20:09:34.737
1 [WIS00002] B2ST4 2011-12-01 20:09:34.737 表wits_86 自动生成GUID 井名WID 时间 (time) 油嘴Nozzle
242342 B1ST4 2012-08-24 16:45:31.600 1616
大家不难看出.....list是主表,,,,找到井名字,通过服务器字段,找到wits_86表中油嘴字段,绑定到gv中,这样怎么实现呢?
public void bind()
{
string con = ConfigurationManager.ConnectionStrings["SQLServerConnectionString"].ConnectionString;
SqlDataAdapter sda = new SqlDataAdapter("select id,TableName,WellId from dbo.db_list", con);
DataSet ds = new DataSet();
sda.Fill(ds);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
SqlConnection scn = new SqlConnection(con);
SqlDataAdapter sda1 = new SqlDataAdapter("select a.id,WellId,b.Nozzle from db_list as a left join " + ds.Tables[0].Rows[i]["TableName"] + ".dbo.wits_86 as b on a.WellId=b.WID", scn);
DataSet ds1 = new DataSet();
sda1.Fill(ds1);
dgUserList.DataSource = ds1;
dgUserList.DataBind();
}
}
我写的代码.后台绑定
但是为什么查出来的都是最后一个库中的数据呢?循环错了?请大神们帮帮忙吧!
最终效果是,石油油井.石油油嘴绑定到GREDVIEW...效果::B1ST4 1616
- 4 回答
- 0 关注
- 298 浏览
添加回答
举报
0/150
提交
取消