/// <summary> /// 获得查询列表 /// </summary> /// <param name="connection">连接</param> /// <param name="transaction">事务</param> /// <param name="WhereQuery">查询条件</param> /// <returns></returns> public int GetQueryCount(IDbConnection connection = null, IDbTransaction transaction = null, string WhereQuery = null) { string Sql = GetQueryCount(WhereQuery); DataTable table; if (transaction == null) { table = SqlHelper.ExecuteReader(Sql, List_SqlParameter.ToArray()); } else { table = SqlHelper.ExecuteReader(Sql, List_SqlParameter.ToArray(), connection, transaction); } return(table.Rows[0][0].ParseInt(0)); }
/// <summary> /// 获得查询分页列表 /// </summary> /// <param name="start">开始位置</param> /// <param name="PageSize">页面大小</param> /// <param name="connection">连接</param> /// <param name="transaction">事务</param> /// <param name="WhereQuery">查询条件</param> /// <returns></returns> public List <T> GetQueryPageList(int start, int PageSize, IDbConnection connection = null, IDbTransaction transaction = null, string WhereQuery = null) { string Sql = GetQuerySqlByPage(start, PageSize, WhereQuery); DataTable table; if (transaction == null) { table = SqlHelper.ExecuteReader(Sql, List_SqlParameter.ToArray()); } else { table = SqlHelper.ExecuteReader(Sql, List_SqlParameter.ToArray(), connection, transaction); } return(table.ConvertToList <T>()); }
public bool GetDeleteResult(IDbConnection connection = null, IDbTransaction transaction = null) { string Sql = GetDeleteSql(); int Count = 0; if (Sql != null) { if (transaction == null) { Count = SqlHelper.ExecuteNonQuery(Sql, List_SqlParameter.ToArray()); } else { Count = SqlHelper.ExecuteNonQuery(Sql, List_SqlParameter.ToArray(), connection, transaction); } } return(Count > 0); }
/// <summary> /// /// </summary> /// <param name="connection"></param> /// <param name="transaction"></param> /// <returns>返回值为-1则执行失败,返回值为0是执行成功 返回值大于0为插入Id</returns> public int GetInsertResult(IDbConnection connection = null, IDbTransaction transaction = null) { string Sql = GetInsertSql(); int? Count = 0; if (Sql != null) { if (transaction == null || connection == null) { var Conntype = SqlHelper.GetConnType(); if (Conntype == Helper.DateBaseType.SQLSERVER || Conntype == Helper.DateBaseType.MYSQL) { Sql += " select @@identity"; Count = SqlHelper.ExecuteReader(Sql, List_SqlParameter.ToArray()).Rows[0][0].ParseInt(); Count = Count == null ? -1 : Count.Value; } else { Count = SqlHelper.ExecuteNonQuery(Sql, List_SqlParameter.ToArray()); Count = Count > 0 ? 0 : -1; } } else { if (connection is SqlConnection || connection is MySqlConnection) { Sql += " select @@identity"; Count = SqlHelper.ExecuteReader(Sql, List_SqlParameter.ToArray(), connection, transaction).Rows[0][0].ParseInt(); Count = Count == null ? -1 : Count.Value; } else { Count = SqlHelper.ExecuteNonQuery(Sql, List_SqlParameter.ToArray(), connection, transaction); Count = Count > 0 ? 0 : -1; } } } return(Count.Value); }