string constr = "database=test;Password=ouyang;User ID=root;server=localhost";//数据库连接语句 MySqlConnection mysqlcon = new MySqlConnection(constr);//建立新的数据库连接
MySqlConnection conn = new MySqlConnection(constr);//连接数据库
conn.Open();//打开数据库
MySqlDataAdapter sda = new MySqlDataAdapter("select * from post", conn);//
DataTable table = new DataTable();
sda.Fill(table);//填充数据库
this.dataGridView1.AutoGenerateColumns = true;
this.dataGridView1.DataSource = table;
this.dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;
conn.Close();//关闭数据库