This article focuses on the actual operation scheme of connecting C # To the MySQL database, as well as the descriptions of several aspects worth your attention in actual operations, this document describes how to connect C # To the MySQL database using an instance.
C # Notes for connecting to the MySQL database:
1、c‑linked mysqldata library to download a mysql-connector-net-6.0.4-noinstall.rar file containing a bunch of dll files. Put them all in ProjectBin and introduce them in ~ For MySQL. data. cf. dll, do not reference it)
2. Note that the c # link to MySQL is different from the link to SQL code.
C # The connection to the MySQL database is as follows:
String MySQLString = "User Id = a; pwd = a; Host = server; Port = server Port number; Database = Database; Character Set = utf8 ";
Next interview example:
- 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();
- }
- }
- }
The above content is an introduction to the C # link to the MySQL database. I hope you will have some gains.
Original article title: C # link to MySQL database
Connection: http://www.cnblogs.com/tsliup/archive/2010/01/14/1647863.html