/// <summary> /// 普通无分页查询 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sql"></param> /// <returns></returns> public static List <T> GetEntitiesListByDB <T>(string sql) { IRDBHelper helper = null; List <T> list = new List <T>(); try { string strCon = ManageConfig.instance.GetConnectionStrings("SHHConnection"); helper = RDBFactory.CreateDbHelper(strCon, DatabaseType.MSSQL); DataTable dataTable = helper.ExecuteDatatable("table", sql, true); list = TBToList.ToList <T>(dataTable); return(list); } catch (Exception ex) { LogAPI.Debug(ex); return(list); } finally { if (helper != null) { helper.DisConnect(); helper = null; } } }
public List <Share_County> GetCountyByCode(string code) { string sql = "select top 1 * from Share_County where code=@code"; SqlParameter[] parameters = { new SqlParameter("@code", code) }; DataTable dt = SqlHelper.GetDataTable(CommandType.Text, sql, parameters); IList <Share_County> IList = new TBToList <Share_County>().ToList(dt); return(IList.ToList()); }
/// <summary> /// RDBHelper 查询分页 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sql">sql语句</param> /// <param name="skip">页数</param> /// <param name="take">每页显示条数</param> /// <param name="count">总数</param> /// <returns></returns> public static List <T> GetEntitiesListByDB <T>(string sql, int skip, int take, out int count) { IRDBHelper helper = null; List <T> list = new List <T>(); try { string strCon = ManageConfig.instance.GetConnectionStrings("SHHConnection"); helper = RDBFactory.CreateDbHelper(strCon, DatabaseType.MSSQL); if (helper != null) { string countSQL = string.Format("select count(1) as NUM from({0})", sql); DataTable dt = helper.ExecuteDatatable("table", countSQL, true); if (dt != null && dt.Rows.Count > 0) { count = int.Parse(dt.Rows[0]["NUM"].ToString()); } else { count = 0; LogAPI.Debug("查询总数失败!"); } //分页查询 string strBegin = "select * from (select a.* ,rownum rn from ( "; string strEnd = string.Format(")a where rownum < {0} ) where rn>{1} ", take, skip); string querySQL = strBegin + sql + strEnd; DataTable dataTable = helper.ExecuteDatatable("table", querySQL, true); list = TBToList.ToList <T>(dataTable); } else { count = 0; LogAPI.Debug("数据库打开失败!"); } return(list); } catch (Exception ex) { count = 0; LogAPI.Debug("查询受理列表异常:"); LogAPI.Debug(ex); return(list); } finally { if (helper != null) { helper.DisConnect(); helper = null; } } }