1

我正在使用天蓝色的网页。这是我的代码的一部分:

 using (SqlConnection conn = new SqlConnection("my connection string"))
            {
                SqlCommand cmd = new SqlCommand("SELECT * FROM Students", conn);
                conn.Open();
                SqlDataAdapter _adp = new SqlDataAdapter(cmd);
                DataTable ds = new DataTable();
                _adp.Fill(ds);
                GridView1.DataSource = ds;

                GridView1.DataBind();
            }

当然,不是“我的连接字符串”,而是真正的连接字符串......

问题是页面加载但由于某种原因没有gridview ...

任何帮助都会很棒,谢谢

编辑:我也尝试过使用数据集,如下所示:

 using (SqlConnection conn = new SqlConnection("my connection string"))
            {
                SqlCommand cmd = new SqlCommand("SELECT * FROM Students", conn);
                conn.Open();
                SqlDataAdapter _adp = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                _adp.Fill(ds);
                GridView1.DataSource = ds.Tables[0];

                GridView1.DataBind();
            }
4

1 回答 1

0

尝试 GridView1.DataSource = ds.Tables[0];

整个代码如下所示:

using (SqlConnection conn = new SqlConnection("my connection string"))
            {
                SqlCommand cmd = new SqlCommand("SELECT * FROM Students", conn);
                conn.Open();
                SqlDataAdapter _adp = new SqlDataAdapter(cmd);
                DataSet ds = new DataTable();
                _adp.Fill(ds);
                GridView1.DataSource = ds.Tables[0];

                GridView1.DataBind();
            }
于 2013-05-16T06:23:00.303 回答