C# 链接MySQL数据库的实现步骤有哪些?


  本文标签:链接MySQL数据库

  此文章抓主要介绍的是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";

  

  下面试个实例:

  

  

  1. using MySQL.Data.MySQLClient;  
  2. namespace Discuz  
  3. {  
  4. public partial class _Default : System.Web.UI.Page  
  5. {  
  6. protected void Page_Load(object sender, EventArgs e)  
  7. {  
  8. if (!Page.IsPostBack)  
  9. {  
  10. this.Bind();  
  11. }  
  12. }  
  13. public void Bind()  
  14. {  
  15. string MySQLString = "User Id=dis;pwd=sa;Host=1.2.3.4;Port=6033;Database=dis;Character Set=utf8";  
  16. MySQLConnection conn = new MySQLConnection(MySQLString);  
  17. conn.Open();  
  18. 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";  
  19. MySQLDataAdapter sda = new MySQLDataAdapter(bb, conn);  
  20. DataSet ds = new DataSet();  
  21. sda.Fill(ds, "T");  
  22. this.GridView1.DataSource = ds;  
  23. this.GridView1.DataBind();  
  24. conn.close();  
  25. }  
  26. }  
  27. }  

  

  以上的相关内容就是对C# 链接MySQL数据库的介绍,望你能有所收获  。

  原文标题:C# 链接MySQL数据库

  连接:http://www.cnblogs.com/tsliup/archive/2010/01/14/1647863.html