天下之事常成于困约,而败于奢靡。这篇文章主要讲述Dapper的简单使用(初学者归纳)相关的知识,希望能为你提供帮助。
Dapper的简单使用(初学者归纳)//引用:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Model;
using Dapper;
//建立数据库连接
public static SqlConnection sqlconn()
{
string ConnString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
var conntion = new SqlConnection(ConnString);
conntion.Open();
return conntion;
}
//列表
public List<
User>
GetList()
{
using (IDbConnection con = UserDal.sqlconn())
{
string sqlcommandtex = "select * from tb_User";
List<
User>
userlist = SqlMapper.Query<
User>
(con, sqlcommandtex).ToList();
return userlist;
}
}
【Dapper的简单使用(初学者归纳)】//删除
public int del(int id)
{
using (IDbConnection con = UserDal.sqlconn())
{
string comm = "delete from tb_User where id = @id";
int res = con.Execute(comm, new { id = id });
return res;
}
}
//参数列表
public User GetUser(int id)
{
using(IDbConnection con = UserDal.sqlconn())
{
string sql = "select * from tb_User where [email
protected]";
User q = con.Query<
User>
(sql, new { id = id }).SingleOrDefault();
return q;
}
}
//修改
public int Upd(User qq)
{
using(IDbConnection con = UserDal.sqlconn())
{
string sql = "update tb_User set [email
protected],[email
protected],[email
protected] where [email
protected]";
int q = con.Execute(sql, qq);
return q;
}
}
推荐阅读
- WINFORM Application.Exit()
- 解决Android Studio启动项目后一直处于refreshing 'View' gradle project,快速解决亲测有效
- Android零基础入门第45节(GridView简单使用)
- 安卓屏幕旋转时,禁止Activity重新加载
- AndroidStudio2.3.3 打 .aar 包给 unity5.6.2 调用
- android ndk-build 编译静态库libxx.a 以及Android studio openssl 静态库配置(cmake)
- android集成pdf显示与批注注释功能
- android 字符串
- app发布流程