C# 鏈接MySQL數(shù)據(jù)庫的實(shí)現(xiàn)步驟有哪些?
此文章抓主要介紹的是C# 鏈接MySQL數(shù)據(jù)庫的實(shí)際操作方案,以及在其實(shí)際操作中值得我們大家注意的幾個(gè)方面的描述,本文主要是以實(shí)例的方式來引出C# 鏈接MySQL數(shù)據(jù)庫的實(shí)際操作流程。
C# 鏈接MySQL數(shù)據(jù)庫只得注意的幾點(diǎn):
1、C#鏈接MySQL數(shù)據(jù)庫要在網(wǎng)上下載一個(gè)MySQL-connector-net-6.0.4-noinstall.rar 這里面放的都是一堆dll .將他們?nèi)糠旁赑rojectBin 然后在VS里引入一下就OK啦~ 對(duì)了MySQL.data.cf.dll這個(gè)除外(不要引用)
2、進(jìn)行數(shù)據(jù)庫鏈接的時(shí)候注意了,c#鏈接MySQL是和鏈接SQl的代碼是不一樣的。
c#鏈接MySQL數(shù)據(jù)庫是這樣的:
string MySQLString = "User Id=a;pwd=a;Host=服務(wù)器;Port=服務(wù)器端口號(hào);Database=數(shù)據(jù)庫;Character Set=utf8";
下面試個(gè)實(shí)例:
- using MySQL.Data.MySQLClient;
- namespace Discuz
- {
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!Page.IsPostBack)
- {
- this.Bind();
- }
- }
- public void Bind()
- {
- string MySQLString = "User Id=dis;pwd=sa;Host=1.2.3.4;Port=6033;Database=dis;Character Set=utf8";
- MySQLConnection conn = new MySQLConnection(MySQLString);
- conn.Open();
- string bb = "SELECT p.author, p.message FROM cdb_threads AS t INNER JOIN cdb_posts AS p ON t.tid = p.tid where t.fid = 34 and digest !=0";
- MySQLDataAdapter sda = new MySQLDataAdapter(bb, conn);
- DataSet ds = new DataSet();
- sda.Fill(ds, "T");
- this.GridView1.DataSource = ds;
- this.GridView1.DataBind();
- conn.close();
- }
- }
- }
以上的相關(guān)內(nèi)容就是對(duì)C# 鏈接MySQL數(shù)據(jù)庫的介紹,望你能有所收獲。
原文標(biāo)題:C# 鏈接MySQL數(shù)據(jù)庫
連接:http://www.cnblogs.com/tsliup/archive/2010/01/14/1647863.html
【編輯推薦】
- jsp MySQL 中的中文問題的實(shí)際解決
- .NET訪問MySQL數(shù)據(jù)庫的經(jīng)驗(yàn)漫談
- Java連接MySQL 數(shù)據(jù)庫的連接步驟
- MySQL存儲(chǔ)過程的創(chuàng)建步驟描述
- MySQL 數(shù)據(jù)庫命令的實(shí)際操作流程