C#連接MySql數(shù)據(jù)庫的方法
作者:佚名
本文介紹C#連接MySql數(shù)據(jù)庫的方法-用MySQLDriverCS連接MySQL數(shù)據(jù)庫,以及介紹然后將MySQLDriver.dll添加引用到項目中。
C#連接MySql數(shù)據(jù)庫的方法-用MySQLDriverCS連接MySQL數(shù)據(jù)庫。
先下載和安裝MySQLDriverCS,在安裝文件夾下面找到MySQLDriver.dll,然后將MySQLDriver.dll添加引用到項目中。
注:我下載的是版本是 MySQLDriverCS-n-EasyQueryTools-4.0.1-DotNet2.0.exe
C#連接MySql數(shù)據(jù)庫代碼:
- usingSystem;
- usingSystem.Collections.Generic;
- usingSystem.ComponentModel;
- usingSystem.Data;
- usingSystem.Data.Odbc;
- usingSystem.Drawing;
- usingSystem.Linq;
- usingSystem.Text;
- usingSystem.Windows.Forms;
- usingMySQLDriverCS;
- namespacemysql{
- publicpartialclassForm1:Form{
- publicForm1(){
- InitializeComponent();
- }
- privatevoidForm1_Load(objectsender,EventArgse){
- MySQLConnectionconn=null;
- conn=newMySQLConnection(newMySQLConnectionString
("localhost","inv","root","831025").AsString);- conn.Open();
- MySQLCommandcommn=newMySQLCommand("setnamesgb2312",conn);
- commn.ExecuteNonQuery();
- stringsql="select*fromexchange";
- MySQLDataAdaptermda=newMySQLDataAdapter(sql,conn);
- DataSetds=newDataSet();
- mda.Fill(ds,"table1");
- this.dataGrid1.DataSource=ds.Tables["table1"];
- conn.Close();
- }
- }
- }
以上介紹C#連接MySql數(shù)據(jù)庫的方法
【編輯推薦】
責(zé)任編輯:佚名
來源:
51CTO.com