/// <summary> /// 分页方法 /// </summary> /// <param name="sql"></param> /// <param name="ai_PageSize">每页行数</param> /// <param name="ai_PageIndex">当前页数</param> /// <param name="ai_totalrow">总行数</param> /// <returns></returns> public static DataTable ExecuteDataTable(string sql, int ai_PageSize, int ai_PageIndex, ref int ai_totalrow) { SqlErr = ""; if (ai_PageSize > 20000) { ai_PageSize = 20000; } DataTable dt = new DataTable(); AccessDB db = new AccessDB(connStr); if (sql.IndexOf("limit") > 0) { sql = sql.Substring(0, sql.IndexOf("limit")); } try { ai_totalrow = db.ExecuteQueryNum(sql); if (ai_PageIndex == 1) { sql += " limit 0," + ai_PageSize; } else { sql += " limit " + (ai_PageIndex * ai_PageSize - 1) + "," + ai_PageSize; } dt = db.ExecuteQueryDataTable(sql); return dt; } catch (Exception e) { SqlErr = e.Message; return dt; } finally { db.CloseSqlConnection(); } }
/// <summary> /// 返回受影响行数 /// </summary> /// <param name="sql"></param> /// <returns></returns> public static int ExecuteNum(string sql) { SqlErr = ""; if (sql.ToLower().IndexOf("count(*)") > 0) { try { return int.Parse(ExecuteScalar(sql)); } catch (Exception ex) { SqlErr = ex.Message; } } AccessDB db = new AccessDB(connStr); int count; try { count = db.ExecuteQueryNum(sql); return count; } catch (Exception e) { SqlErr = e.Message; return -1; } finally { db.CloseSqlConnection(); } }
/// <summary> /// 返回受影响行数 /// </summary> /// <param name="sql"></param> /// <param name="valuse"></param> /// <returns></returns> public static int ExecuteNum(string sql, SqliteParameter[] valuse) { if (sql.ToLower().IndexOf("count(*)") > 0) { try { return int.Parse(ExecuteScalar(sql, valuse)); } catch { } } AccessDB db = new AccessDB(connStr); int count; try { count = db.ExecuteQueryNum(sql, valuse); return count; } catch { return -1; } finally { db.CloseSqlConnection(); } }