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();
无错误提示,但页面不显示东西. 谢谢!
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();
无错误提示,但页面不显示东西. 谢谢!
"select * from " + g;
有没有返回什么数据
建议在 SQL SERVER里测试一下SQL正确性。
这个sql最后是什么值?单步调试下
页面中什么都没有,表头也没有.谢谢!
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();先这样绑定看看有问题没有
还真有问题,也是没有东西.但我另创建一页,代码如下:
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();
可以显示的,经常出现这种情况.有时,拉控件也就不行了,什么问题呢,我安装的问题吗?