C# DateGridView 数据绑定中多表查询
tab1表结构是类似这样的:
ID Name FatherID
1 a 0
2 b 1
3 c 2
绑定到DataGridView, 我想把 FatherID 列显示的是 FatherID 对应 ID 列的 Name
怎么办呢?
SqlDataAdapter da = new SqlDataAdapter(@ "SELECT * FROM tab1 ", cnt);
SqlCommandBuilder cmdbuilder = new SqlCommandBuilder(da);
DataSet ds= new DataSet();
da.Fill(ds, "tab1 ");
this.datagridview1.DataSource = ds;
------解决方案--------------------select a.ID,a.name,b.name from tab1 as a left join tab1 as b on a.fatherID=b.ID