| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Dapper查询返回datatable数据(带参数) |
| | | /// </summary> |
| | | /// <param name="sql"></param> |
| | | /// <param name="parm"></param> |
| | | /// <returns></returns> |
| | | public static DataTable selectlist(string sql, Object parm) |
| | | { |
| | | //sql语句 |
| | | using (IDbConnection conn = sqlConnection()) |
| | | { |
| | | try |
| | | { |
| | | DataTable table = new DataTable(); |
| | | var data = conn.ExecuteReader(sql, parm); |
| | | table.Load(data); |
| | | return table; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //创建日志记录组件实例 |
| | | LogHelper.WriteLog(ex); |
| | | throw ex; |
| | | } |
| | | finally |
| | | { |
| | | conn.Dispose(); |
| | | conn.Close(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Dapper查询返回datatable数据(不带参数) |
| | | /// </summary> |
| | | /// <param name="sql"></param> |
| | |
| | | |
| | | |
| | | /// <summary> |
| | | /// Dapper插入 返回自增主键Id |
| | | /// Dapper插入 返回自增主键Id(备份) |
| | | /// </summary> |
| | | /// <param name="sql"></param> |
| | | /// <param name="parameter"></param> |
| | | /// <param name="tableName">待插入数据的表名</param> |
| | | /// <returns></returns> |
| | | public static int insertReturnId(string sql, Object parameter, String tableName) |
| | | public static int insertReturnId0(string sql, Object parameter, String tableName) |
| | | { |
| | | |
| | | int result = 0; |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Dapper插入 返回自增主键Id |
| | | /// </summary> |
| | | /// <param name="tableName">待插入数据的表名</param> |
| | | /// <returns></returns> |
| | | public static int insertReturnId(String tableName) |
| | | { |
| | | |
| | | int result = 0; |
| | | using (IDbConnection conn = sqlConnection()) |
| | | { |
| | | try |
| | | { |
| | | if (result == 0) |
| | | { |
| | | result = conn.Query<int>("select ident_current(@table)", new { table = tableName }).Single<int>(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //创建日志记录组件实例 |
| | | LogHelper.WriteLog(ex); |
| | | throw ex; |
| | | } |
| | | finally |
| | | { |
| | | conn.Dispose(); |
| | | conn.Close(); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | public static DataTable lissql(string sql) |
| | | { |
| | | //sql语句 |
| | | using (IDbConnection conn = sqlConnection()) |
| | | { |
| | | try |
| | | { |
| | | DataTable table = new DataTable(); |
| | | //var data = conn.ExecuteReader(sql, parm); |
| | | var res = conn.ExecuteReader(sql);//sql 存储过程 |
| | | table.Load(res); |
| | | return table; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //创建日志记录组件实例 |
| | | LogHelper.WriteLog(ex); |
| | | throw ex; |
| | | } |
| | | finally |
| | | { |
| | | conn.Dispose(); |
| | | conn.Close(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |