wuliws 发表于 2018-10-1 14:38:00

在c#中如何连接Mysql数据库


[*]  在mysql官网https://dev.mysql.com/downloads/connector/net 下载".NET&MONO"版本的mysql connector。
[*]  在c#的reference中添加v4文件夹中所有的dll的引用。v4对应".NET FRAME4",在project中的属性中选择对应的".NET FRAME"版本。
[*]  在程序首列添加"using MySql.Data.MySqlClient;"
[*]  连接代码如下所示。
  String str = "Server=localhost; Database = php; Uid = root; Pwd = redhat";
  try
  {
  msc = new MySqlConnection(str);
  msc.Open();
  if (msc.State == ConnectionState.Open)
  {
  MessageBox.Show("database is open");
  }
  }
  catch
  {
  MessageBox.Show("database is open error!");
  }

页: [1]
查看完整版本: 在c#中如何连接Mysql数据库