Home >Database >Mysql Tutorial >C#连接mysql数据库_MySQL

C#连接mysql数据库_MySQL

WBOY
WBOYOriginal
2016-06-01 13:04:341152browse

1. 需要驱动

请下载 MySQLDriverCS-n-EasyQueryTools,版本自己选择就好

2.项目导入驱动

1)引用里增加

\

选择

\

图中浅色,ok。

3. 代码块

添加头文件

using MySQLDriverCS;

连接数据库代码

 

            MySQLConnectionString tConnStr = new MySQLConnectionString("localhost","wxj","root", "", 3306);
            MySQLConnection tConn = new MySQLConnection(tConnStr.AsString);


            tConn.Open();  //打开连接


            string tCmd = "SELECT * FROM wxj.stu;";  //命令语句
            MySQLCommand cmd = new MySQLCommand(tCmd, tConn);  //在定义的tConn对象上执行查询命令
            MySQLDataReader tReader = cmd.ExecuteReaderEx();


            if (tReader.Read())   // 一次读一条记录
            {
                Response.Write(tReader["name"].ToString());
            }
            tConn.Close();//重要!要及时关闭
            tReader.Close();

剩下的逻辑功能就看自己的需求了

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn