Home >Database >Mysql Tutorial >FluentData 连接Mysql_MySQL

FluentData 连接Mysql_MySQL

WBOY
WBOYOriginal
2016-06-01 13:12:351263browse

FluentData 框架连接Mysql的示例

先写一个方法

public IDbContext QueryDB()        {            return new DbContext().ConnectionStringName("constr", new MySqlProvider());        }

调用示例
DataTable dt = QueryDB().Sql("select * from user").QuerySingle<datatable>();</datatable>

web.config的连接字符串的配置

<connectionstrings>    <add name="constr" connectionstring="Server=服务器地址;Database=表名;Uid=用户名;Pwd=密码;" providername="MySql.Data.MySqlClient;"></add>  </connectionstrings>

从网上下载Mysql.Data.dll 引用

到这里并不算完,如果运行程序会出现‘找不到请求的 .Net Framework Data Provider’的提示。这里需要下载驱动。

下载地址:http://dev.mysql.com/downloads/connector/net/

下载安装,完成。

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