string conn = System.Configuration.ConfigurationManager.ConnectionStrings["cityConnectionString"].ToString();       
        SqlConnection con = new SqlConnection(conn);
        con.Open();  //连接没问题        string sql22 = "select  * from sys.tables where type='U'";
        DataSet ds22 = new DataSet();
        SqlDataAdapter da22 = new SqlDataAdapter();
        da22.SelectCommand = new SqlCommand(sql22, con);
        da22.Fill(ds22, "c");
        string g = ds22.Tables["c"].Rows[0][0].ToString(); //可以取到值
        
        string sql = "select * from " + g;
        DataSet ds = new DataSet();        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = new SqlCommand(sql, con);
        da.Fill(ds, "b");        this.GridView1.DataSource = ds.Tables["b"].DefaultView;
        GridView1.DataBind();
     无错误提示,但页面不显示东西. 谢谢!

解决方案 »

  1.   

    在SQL 里边测试一下
     "select * from " + g;
    有没有返回什么数据
      

  2.   

    很可能根本没有读得出数据。
    建议在 SQL SERVER里测试一下SQL正确性。
      

  3.   

    页面不显示是整个表格都不显示还是只显示表头?PS:LZ做人要厚道!
      

  4.   

    string sql = "select * from " + g;
    这个sql最后是什么值?单步调试下
      

  5.   

    sql语句正确,可以取到值.  g为 cityy数据库的 city表  数据中测试select * from city有值.
    页面中什么都没有,表头也没有.谢谢!
      

  6.   

    string conn = System.Configuration.ConfigurationManager.ConnectionStrings["cityConnectionString"].ToString();       
            SqlConnection con = new SqlConnection(conn);
            con.Open();  //连接没问题        /*
            string sql22 = "select  * from sys.tables where type='U'";
            DataSet ds22 = new DataSet();
            SqlDataAdapter da22 = new SqlDataAdapter();
            da22.SelectCommand = new SqlCommand(sql22, con);
            da22.Fill(ds22, "c");
            string g = ds22.Tables["c"].Rows[0][0].ToString(); //可以取到值
            */
            string sql = "select * from city";
            DataSet ds = new DataSet();        SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = new SqlCommand(sql, con);
            da.Fill(ds, "b");        this.GridView1.DataSource = ds.Tables["b"].DefaultView;
            GridView1.DataBind();先这样绑定看看有问题没有
      

  7.   

    webwait(webwei)
    还真有问题,也是没有东西.但我另创建一页,代码如下:
    string conn = System.Configuration.ConfigurationManager.ConnectionStrings["cityConnectionString"].ToString();       
            SqlConnection con = new SqlConnection(conn);
            con.Open();
     string sql = "select * from city";
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = new SqlCommand(sql, con);
            da.Fill(ds, "b");
            this.GridView1.DataSource = ds.Tables["b"].DefaultView;
            GridView1.DataBind();
    可以显示的,经常出现这种情况.有时,拉控件也就不行了,什么问题呢,我安装的问题吗?
      

  8.   

    谢谢大家了.我已经解决了,我删除了GridView1,有重拉了控件,就没问题了.各位接分吧!