1. 程式人生 > >winFormToMysql&&幾個控件的數據綁定

winFormToMysql&&幾個控件的數據綁定

base rgs private bindings mage color img rom images

運行圖:

技術分享

代碼:

 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

winFormToMysql&&幾個控件的數據綁定