运行图:
代码:
1 private void button1_Click(object sender, EventArgs e) 2 { 3 string str = "database=csharp;data source=localhost;user id=root;password=root"; 4 MySqlConnection con = new MySqlConnection(str); 5 con.Open(); 6 if (con.State == ConnectionState.Open) { 7 label1.Text = "success"; 8 9 string mysql="select * from student"; 10 MySqlCommand cmd = new MySqlCommand(mysql, con); 11 MySqlDataAdapter da = new MySqlDataAdapter(cmd); 12 DataSet ds = new DataSet(); 13 14 da.Fill(ds, "haha"); 15 dataGridView1.DataSource = ds; 16 dataGridView1.DataMember = "haha"; 17 18 textBox1.DataBindings.Clear(); 19 textBox1.DataBindings.Add("text", ds, "haha.name"); 20 21 comboBox1.DataSource = ds; 22 comboBox1.DisplayMember = "haha.name"; 23 comboBox1.ValueMember = "haha.name"; 24 }
MySql.Data.dll下载位置:http://download.csdn.net/detail/u010940770/6519079
时间: 2024-10-24 06:34:46