SQL里有3个不同的表,要进行绑定到DATAGRID里。这是2个表可以关联。
//SqlDataAdapter mycom=new SqlDataAdapter(String.Format(""SELECT * FROM XXX1 JOIN XXXX2 ON XXXX1.字段 = xxx2.字段2 order by idd DESC""),con);
DataSet ds2=new DataSet();
mycom.Fill(ds2,"XXX1");
int i;
int RowCount;
string[] strTemp = new string[ds2.Tables[0].Columns.Count];
RowCount = ds2.Tables[0].Rows.Count;
for(i=0;i<5-RowCount;i++)
{
ds2.Tables[0].Rows.Add(strTemp);
}
this.DATAGRID.DataSource=ds2;
this.DATAGRID.DataBind();这个2个表可以关联。但是如果遇到3个表该怎么样写可以绑定到DATAGRID...还有如果3个表里有相同字段名字怎么过滤
------解决方案--------------------------------------------------------
三表联结查询和两表没什么区别,怕有重名那就取别名
- SQL code
SELECT A.name AS name1,B.name AS name2,C.name as name3FROM A,B,CWHERE A.parentid=B.id AND B.Parentid=C.id
------解决方案--------------------------------------------------------
三个表,就不可以关联了么
你直接把sql语句写成三个表关联不行了么?
SELECT *
FROM XXX1,XXXX2,XXXX3
WHERE XXXX1.字段 = xxx2.字段2 AND XXXX2.字段2= XXXX3.字段3
order by idd DESC
------解决方案--------------------------------------------------------
SELECT A.name AS name1,B.name AS name2,C.name as name3
FROM A,B,C
WHERE A.parentid=B.id AND B.Parentid=C.id
用这个