怎么实现数据库多表的内查询数据在c#里面显示出来
string cnst = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=StuMagSys;Data Source=PC-201006091555"; //数据库连接SqlConnection str = new SqlConnection(cnst);
str.Open();
string sql = "select s.Student_id as 学号,g.Student_name as 姓名 ,j.Course_name as 课程,s.Grade as 成绩,s.SC_semester as 学期,s.SC_year as 学年from Student_course as s,course j , Student g "+
"where s.Course_id=j.Course_id and g.Student_id=s.Student_id";
SqlCommand obj = new SqlCommand(sql, str);
SqlDataAdapter c = new SqlDataAdapter();
c.SelectCommand = obj;
DataSet dr = new DataSet();
c.Fill(dr, "Student");
dataGridView1.DataSource = dr;
dataGridView1.DataMember = "Student";
因为我这段代码的数据库执行语句是多表的内查询, 到C#dataGridView1控件显示数据的时候不知道是显示哪个表的数据,显示其中的哪个表都出错!
请各位高手帮我看一下代码,帮我解决一下这个问题.谢谢!
[ 本帖最后由 zxx546 于 2010-12-25 14:55 编辑 ]