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

  1. 在mysql官网https://dev.mysql.com/downloads/connector/net 下载".NET&MONO"版本的mysql connector。php

  2. 在c#的reference中添加v4文件夹中全部的dll的引用。v4对应".NET FRAME4",在project中的属性中选择对应的".NET FRAME"版本。mysql

  3. 在程序首列添加"using MySql.Data.MySqlClient;"sql

  4. 链接代码以下所示。c#

            String str = "Server=localhost; Database = php; Uid = root; Pwd = redhat";ide

            tryci

            {get

                msc = new MySqlConnection(str);it

                msc.Open();io

                if (msc.State == ConnectionState.Open)class

                {

                    MessageBox.Show("database is open");

                }

            }

            catch

            {

                MessageBox.Show("database is open error!");

            }

相关文章
相关标签/搜索