1.引入Dapper。
2.链接字符(支持中文)
“server=127.0.0.1;uid=root;pwd=;database=test;Charset=utf8”
3.创建链接生成Connect
public IDbConnection GetConn()
{
IDbConnection conn = null;
try
{
using (conn = new MySqlConnection(Constr))
{
conn.Open();
}
}
catch (Exception ex)
{
string ErrMsg = string.Format("数据库连接错误,错误原因是:{0}",ex.Message);
throw new Exception(ErrMsg);
}
return conn;
}
-
获取list的方式是使用query
using (conn = new MySqlConnection(Constr)) { conn.Open(); string sql = "SELECT * FROM `userinfo`"; return conn.Query<TestModel>(sql); }
来源:CSDN
作者:kingwebo'sZone
链接:https://blog.csdn.net/weixin_40029679/article/details/104439710