文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>C#实现oracle分页函数

C#实现oracle分页函数

时间:2011-06-01  来源:一笑&

在网上找了大半天,都没发现有oracle的分页函数C#实习方法, 最气人的是找到一个例子,居然根本无法通过编译的,但却被莫名其妙的转了几遍。 还是自己动手,丰衣足食。 谁有更好的分页函数,请在回复中给我吧! 调用分页函数
            Database db = new Database();
string fenye=string.Empty;
fenye
= db.JoinPageSQL("","TEST","","order by ID Desc",2,2);
OracleDataReader odr
= db.ExecuteReader(fenye);
while (odr.Read())
{
Console.WriteLine(odr[
0].ToString()+odr[1].ToString ());
}
odr.Close();
这里Order调用的时候输入的格式为: Order by xx 【desc或者ASC】            public string JoinPageSQL(string Field, string TableName, string Where, string Order, int CurrentPage, int PageSize)
{
//SELECT * FROM (SELECT A.*, ROWNUM RN FROM (SELECT * FROM system.tabx) A WHERE ROWNUM <= 30)WHERE RN >= 10
string sql = null;
Field
=Field == "" ? "A.*" : Field;
Where
= Where == "" ? "1=1" : Where;

sql
= "select * from (";
sql
+= "select " + Field +
",rownum rn from(select * from " + TableName+" where "+Where +") A ";
sql
+= "where rownum<=" + CurrentPage * PageSize + Order+")" + "where rn>" + (CurrentPage - 1) * PageSize + " ";

return sql;
}
  扩展的方法
当多表查询的时候,可以任意的指定from的来源,然后
可以任意的查询字段 Field


/// <param name="SelectSql">自动代码生成里from的来源,select查询结果</param>public string JoinPageSQL(string Field,string SelectSql, string Order, int CurrentPage, int PageSize) { //SELECT * FROM (SELECT A.*, ROWNUM RN FROM (SELECT * FROM system.tabx) A WHERE ROWNUM <= 30)WHERE RN >= 10 string sql = null; Field = Field == "" ? "A.*" : Field; SelectSql = SelectSql == "" ? "1=1" : SelectSql; sql = "select * from ("; sql += "select " + Field + ",rownum rn from( " + SelectSql + ") A "; sql += "where rownum<=" + CurrentPage * PageSize + Order + ")" + "where rn>" + (CurrentPage - 1) * PageSize + " "; return sql; }
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载