C # implement the Oracle paging Function

Source: Internet
Author: User
public class PageUtil{    // Methods    public static DataView GetListForPage(int index, int pagesize, string tabname, string key, string condition, string sortindex, ref int count)    {        int rscount = 0;        StringBuilder strSql = new StringBuilder();        OracleDataReader sdr = null;        if (condition.Length > 0)        {            condition = " and " + condition;        }        strSql.Append("select count(*) from " + tabname + " where 1=1" + condition);        sdr = DbHelperOra.ExecuteReader(strSql.ToString());        if (sdr.Read())        {            rscount = Convert.ToInt32(sdr[0]);        }        sdr.Close();        count = rscount;        int maxpage = ((rscount + pagesize) - 1) / pagesize;        if ((index + 1) >= maxpage)        {            index = maxpage - 1;        }        if (index < 0)        {            index = 0;        }        int start = (index * pagesize) + 1;        int end = ((index + 1) * pagesize) + 1;        string sql = "SELECT * FROM (SELECT A.*, ROWNUM RN FROM (SELECT * FROM " + tabname + " where 1=1 " + condition + " order by " + sortindex + " desc) A WHERE ROWNUM < " + end.ToString() + ") WHERE RN >= " + start.ToString();        DataSet ds = new DataSet();        ds = DbHelperOra.Query(sql);        if (ds.Tables.Count > 0)        {            return ds.Tables[0].DefaultView;        }        return null;    }}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.