.net2.0連接Mysql5數(shù)據(jù)庫配置

? ? ? ? ? 本人一直比較喜歡Mysql,主要原因就是:1.數(shù)據(jù)庫體積小。2.數(shù)據(jù)庫開源免費(fèi)。3.數(shù)據(jù)庫有許多好用的客戶端工具。

4.跨平臺。5.性能和功能相對強(qiáng)大(不可能去和那些重量級的比)。6.容易移植部署安裝也簡單。所以我做的小項(xiàng)目一般也會

首選使用Mysql。最近在使用.net+sqlserver05的組合,但是苦于sqlserver企業(yè)版,標(biāo)準(zhǔn)版僅支持server 03,我的臺機(jī)是XP,

所以很是郁悶,裝了個Express,功能少太多了。用的也不爽。卸也卸不干凈。最后甚至考慮遠(yuǎn)程用別人的Sqlserver2000企業(yè)

版。但是因?yàn)?net也同樣支持mysql連接,所以就上網(wǎng)搜了搜實(shí)現(xiàn),和所需工具。確實(shí)沒啥技術(shù)含量。看來俺以后也可以考慮

.net+Mysql的組合。網(wǎng)上這方面資料非常多,俺也僅僅記錄一下自己的實(shí)現(xiàn)體會。不會的參考下,會的繞道就好。

下載工具:

Mysql的connector/net5.0下載地址:
http://dev.mysql.com/get/Downloads/Connector-Net/mysql-connector-net-5.0.6.zip/from/pick
下載后直接安裝就可以。

安裝完了,加入引用到項(xiàng)目,就可以使用了。

下面曬一下代碼:實(shí)現(xiàn)功能就是從Mysql中讀取一張用戶表,并且執(zhí)行Mysql的存儲過程。例子不在難,成功則靈。本機(jī)

都執(zhí)行通過了。本機(jī)環(huán)境:XP+Mysql5+VS05+C#(ASP.NET2.0)

代碼很簡單,主要是測試用:

using?System; using?System.Data; using?System.Configuration; using?System.Collections; using?System.Web; using?System.Web.Security; using?System.Web.UI; using?System.Web.UI.WebControls; using?System.Web.UI.WebControls.WebParts; using?System.Web.UI.HtmlControls; using?System.Data.SqlClient; using?MySql.Data.MySqlClient; namespace?ConnectMysql { ????public?partial?class?_Default?:?System.Web.UI.Page ????{ ????????protected?void?Page_Load(object?sender,?EventArgs?e) ????????{ ????????????if(!Page.IsPostBack){ ????????????????MySqlConnection?con?=?DB.createCon(); ????????????????string?sql?=?"select?*?from?t_user"; ????????????????MySqlDataAdapter?mda?=?new?MySqlDataAdapter(sql,con); ????????????????DataSet?ds?=?new?DataSet(); ????????????????mda.Fill(ds,?"user"); ????????????????this.GridView1.DataSource?=?ds; ????????????????this.GridView1.DataBind();? ????????????} ????????} ????????protected?void?Button1_Click(object?sender,?EventArgs?e) ????????{ ????????????MySqlConnection?con?=?DB.createCon(); ????????????MySqlCommand?cmd?=?new?MySqlCommand("getUsername",?con); ????????????cmd.CommandType?=?CommandType.StoredProcedure; ????????????con.Open(); ????????????try ????????????{ ????????????????MySqlDataReader?dr?=?cmd.ExecuteReader(); ????????????????this.GridView2.DataSource?=?dr; ????????????????this.GridView2.DataBind(); ????????????????con.Close(); ????????????} ?????????????catch(Exception?ex) ????????????{ ????????????????ex.ToString(); ????????????????con.Close(); ????????????} ????????} ????} }

題目還是挺吸引人的,其實(shí).net1.0連Mysql其實(shí)是一樣一樣的。

本文講解了.net2.0連接Mysql5數(shù)據(jù)庫配置相關(guān)內(nèi)容,更多相關(guān)內(nèi)容請關(guān)注php中文網(wǎng)。

相關(guān)推薦:

cookie 和session 的區(qū)別詳解

cookie 和session 的區(qū)別詳解

cookie 和session 的區(qū)別詳解

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊9 分享