C#连接MySql

1.从http://prdownloads.sourceforge.net/mysqldrivercs/MySQLDriverCS-n-EasyQueryTools-3.0.18.exe?download上下载MySQLDriverCS. 然后安装。
2.从安装目录中MySQLDriverCS.dll.添加到.net的组件 

 1 public void Connect_Net()
 2         {
 3             MySQLConnection mycn = new MySQLConnection(new MySQLConnectionString("localhost", "test", "root", "root", 3306).AsString);
 4             mycn.Open();
 5             MySQLCommand mycm = new MySQLCommand("SELECT * FROM user_message", mycn);
 6             MySQLDataReader reader = mycm.ExecuteReaderEx();
 7             try
 8             {
 9                 while (reader.Read())
10                 {
11                     str = reader.GetString(0) + reader.GetString(1);
12                     textBox2.AppendText(str);
13                 }
14             }
15             catch (Exception e)
16             {
17                 str = e.ToString();
18             }
19             reader.Close();
20             mycn.Close();
21         }

 

 

posted @ 2012-06-09 21:34  honging  阅读(181)  评论(0编辑  收藏  举报