在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!");

            }

相關文章
相關標籤/搜索