using MySql.Data.MySqlClient; string strCon = "server=localhost;user id=root;password=root;database=google;CharSet=gb2312;"; MySqlConnection mysqlcon; //绑定GridView1 public void bind() { string sqlstr = "select * from v_company order by TIME desc"; //防止程序池溢出 using (mysqlcon = new MySqlConnection(strCon)) { MySqlDataAdapter myda = new MySqlDataAdapter(sqlstr, mysqlcon); DataSet myds = new DataSet(); mysqlcon.Open(); myda.Fill(myds, "v_company"); GridView1.DataSource = myds; GridView1.DataKeyNames = new string[] { "id" };//主键 GridView1.DataBind(); } }