此文章抓主要介绍的是C# 链接MySQL数据库的实际操作方案,以及在其实际操作中值得我们大家注意的几个方面的描述,该篇文章主要是以实例的方式来引出C# 链接MySQL数据库的实际操作流程。
C# 链接MySQL数据库只得注意的几点:
1、C#链接MySQL数据库要在网上下载一个MySQL-connector-net-6.0.4-noinstall.rar 这里面放的都是一堆dll .将他们全部放在ProjectBin 然后在VS里引入一下就OK啦~ 对了MySQL.data.cf.dll这个除外(不要引用)
2、进行数据库链接的时候注意了,c#链接MySQL是和链接SQl的代码是不一样的。
c#链接MySQL数据库是这样的:
string MySQLString = "User Id=a;pwd=a;Host=服务器;Port=服务器端口号;Database=数据库;Character Set=utf8";
下面试个实例:
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(); } } }
上面说了这么多内容,是关于对C# 链接MySQL数据库的介绍,不知道各位对MySQL的认识是不是更上一层楼了,时时关注ITJS,学习最新Mysql技术。
原文标题:C# 链接MySQL数据库
连接:http://www.cnblogs.com/tsliup/archive/2010/01/14/1647863.html