C# MySql 连接

1.将MySql.Data.dll引用到你的项目中

   右键工程去完成。

2.using MySql.Data;
  using MySql.Data.MySqlClient;

 

3.

        

 1             MySqlConnection objConn = new MySqlConnection();
 2             objConn.ConnectionString = "Database='main_db';Data Source='localhost';User Id='root';Password='root';charset='utf8';pooling=true";
 3             objConn.Open();
 4             MySqlCommand objCmd = new MySqlCommand("select * from `main_db`.`t_user`", objConn);
 5             MySqlDataReader  r = objCmd.ExecuteReader();
 6             while (r.Read())
 7             {              
 8         
 9                     textBox3.Text = textBox3.Text + r.GetString(0)+r.GetString(1);                     
10 
11             } 
12            objConn.Close();
View Code

测试OK

posted @ 2013-07-10 16:17  wwjdwy  阅读(211)  评论(0编辑  收藏  举报