如题,谢谢,急

解决方案 »

  1.   

    直接绑定不行吗、?
    gridview.datasource=(集合或者table)
    gridview.databind();
      

  2.   

    有代码么?
    参考一下
    谢谢了
    sql查询语句:
    select a.col1,b.col1 from table1 a,table2 b where a.serialno = b.serialno;
      

  3.   

    select a.*,b.* from a,b
    或union
      

  4.   

    select a.col1 as name,b.col1  as name  from table1 a,table2 b where a.serialno = b.serialno;<%#Eval("name")%>
      

  5.   

      OdbcConnection myCon = new OdbcConnection(WebConfigurationManager.ConnectionStrings["stringcon"].ToString());
            myCon.Open();
            try
            {
                string str_sql = "";
                str_sql = sqltext;
                OdbcDataAdapter myData = new OdbcDataAdapter(str_sql, myCon);
                DataSet MyDs = new DataSet();
                myData.Fill(MyDs, "customerinfor");
                GridView1.DataSource = MyDs.Tables["customerinfor"].DefaultView;
                GridView1.DataKeyNames = new string[] { "customerno" };
                GridView1.DataBind();
            }
            catch (Exception p)
            {
            }
            finally
            {
                myCon.Close();
            }一个表,我是这样写的,两个表话
    myData.Fill(MyDs, "customerinfor");
    能这样写么?
      

  6.   

    直接写一个视图也可以啊。
    写了个查询返回一个集合的方法将此方法作为数据源绑定到GridView的DataSource中咯。
    gridview.datasource=(集合或者table)
    gridview.databind();
      

  7.   


    用这种public DataTable GetDate(string where)
            {
                SqlConnection cn = new SqlConnection();
                cn.ConnectionString = "";
                SqlCommand cmd = new SqlCommand();
                DataTable dt = new DataTable();
                SqlDataReader dr = null;
                cmd.CommandText = where;
                cmd.Connection = cn;
                using (dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    dt.Load(dr);
                }
                if (dt.Rows.Count != 0)
                {
                    return dt;
                }
                else
                {
                    return null;
                }        }返回一个DataTable 然后
    this.GridView1.DataSource =GetDate;
    GridView1.DataBind();
    多张表查询可以SQL的 连接 left join or right join or inner join 然后弄好SQL传入到方法里就行了。