如果要返回如下的数据
select a.id,b.name,a.age from a,b where a.id= b.id
这样的查询结果如何显示在DataGrid中
用了datarelation也没有实现,请教大哥.

解决方案 »

  1.   

    private void Page_Load(object sender, System.EventArgs e)
    {
                if(!Page.IsPostBack)
                {
                    DataBind();
                }            
    }private void DataBind()
    {
                string sql="select a.id,b.name,a.age from a,b where a.id= b.id";
                DataSet ds=GetDataSet(sql);
                this.DataGrid1.DataSource=ds;
                this.DataGrid1.DataBind();
    }private DataSet GetDataSet(string sql)
    {
                constring=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
                SqlDataAdapter    sda =new SqlDataAdapter(sql,constring);
                DataSet ds=new DataSet();
                sda.Fill(ds);
                return ds;
    }直接这样绑定就可以了,还有什么需求吗?参考
    http://singlepine.cnblogs.com/articles/266538.html
      

  2.   

    sda.Fill(ds);不需要指定数据table
    sda.fill(ds,"a")