.NET连接MySql数据库

首先要下载并安装Connector/Net 目前最新版本为6.2.3。
http://www.mysql.com/downloads/connector/net/ 
 

添加引用:
  <compilation debug="true">
   <assemblies>
    <add assembly="MySql.Data, Version=6.2.3.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D"/>
   </assemblies></compilation>

配置web.config
<connectionStrings>
  <add name="MySqlDB_L" connectionString="Server=www.denghaigang.com;Port=6033;Database=discuz;Uid=root;Pwd=root;Allow Zero Datetime=true" providerName="MySql.Data.MySqlClient"/>
 </connectionStrings>

好了,开始写程序了

using MySql.Data.MySqlClient;
    MySqlConnection mysqldbconnection = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MySqlDB_L"].ConnectionString);
            mysqldbconnection.Open();

            MySqlDataAdapter mysqlad = new MySqlDataAdapter("select * from cdb_members", mysqldbconnection);
            DataSet user = new DataSet();

            mysqlad.Fill(user,"user");

            GridView1.DataSource = user.Tables["user"];
            GridView1.DataBind();

            mysqldbconnection.Close();

“.NET连接MySql数据库”的2个回复

评论已关闭。