首先引入dapper  PM>Install-Package Dapper (可能会出现因版本问题而安装失败详情见官网:https://stackexchange.github.io/Dapper/)

介绍三种常用的形式

需要引用using System.Data.SqlClient;using System.Data;using Dapper;

        public IEnumerable<T> Querys<T>()
        {//查询结果为IEnumerable类型,T为需要查询表的实体模型
            IDbConnection connection = new SqlConnection("链接字符串");
            return connection.Query<T>("SQL语句");
        }
        public DataTable DataReaders()
        {//查询结果为DataTable类型,内存中数据的一个表
            IDbConnection connection = new SqlConnection("链接字符串");
            var DataReaders = connection.ExecuteReader("SQL语句");
            DataTable dataTable = new DataTable();
            dataTable.Load(DataReaders);return ds;
        }
        public int exes()
        {//结果为sql语句的受影响行数
            IDbConnection connection = new SqlConnection("链接字符串");
            return connection.Execute("SQL语句");
        }

ps:部分代码未补充完整

相关文章:

  • 2022-12-23
  • 2021-09-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-17
  • 2022-12-23
  • 2022-12-23
  • 2021-06-01
  • 2021-08-21
  • 2021-09-27
相关资源
相似解决方案