VS2008中控件gridview的问题
如何用SQL语句从数据库中某个表格里拿出数据放进DATATABLE中然后在赋值给gridview...
如何用SQL语句从数据库中某个表格里拿出数据放进DATATABLE中 然后在赋值给gridview
展开
2个回答
展开全部
string sqlstr = ConfigurationManager.ConnectionStrings["XCEConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(sqlstr);
conn.Open();
string sqlcmd = "select * from Book";
SqlDataAdapter sda = new SqlDataAdapter(sqlcmd, conn);
DataTable myTable = new DataTable();
sda.Fill(myTable);
GridView1.DataSource = myTable;
GridView1.DataBind();
conn.Close();
SqlConnection conn = new SqlConnection(sqlstr);
conn.Open();
string sqlcmd = "select * from Book";
SqlDataAdapter sda = new SqlDataAdapter(sqlcmd, conn);
DataTable myTable = new DataTable();
sda.Fill(myTable);
GridView1.DataSource = myTable;
GridView1.DataBind();
conn.Close();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询