运行图:
代码:
private void button1_Click(object sender, EventArgs e)
{
string str = "database=csharp;data source=localhost;user id=root;password=root";
MySqlConnection con = new MySqlConnection(str);
con.Open();
if (con.State == ConnectionState.Open) {
label1.Text = "success"; string mysql="select * from student";
MySqlCommand cmd = new MySqlCommand(mysql, con);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet(); da.Fill(ds, "haha");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "haha"; textBox1.DataBindings.Clear();
textBox1.DataBindings.Add("text", ds, "haha.name"); comboBox1.DataSource = ds;
comboBox1.DisplayMember = "haha.name";
comboBox1.ValueMember = "haha.name";
}