List condition Paging query

Source: Internet
Author: User

Sql=sqlselect+sqlfrom+sqlwhere+sqlorder

String sql = string. Empty;

String sqlselect = "Select CC." CLASSID,CC. CLASSNAME,CP. Coursename,pp. Title,pp. Releasetime,pp. Ispublic,pp.id as preparationid,cu.id as unitid,cp.id as packid,pp. Examid,pp. Ispractice,pp. Examid ";//Query column

Data sources

String sqlfrom = @ "from Yk_preparation pp--Lesson preparation

Join Yk_courseunit cu on pp. Coureunitid=cu.id--Course Modules

Join Yk_coursepack CP on CU. Coursepackid=cp.id--Course Package

Left joins Yk_courseclass cc on CC. COURSEPACKID=CP. Id ";

StringBuilder sqlwhere = new StringBuilder ();//Query condition

String Sqlorder = String. empty;//sort

String SqlCount = String. empty;//total number of records queried

Sqlwhere.append ("where pp. ' Status ' = 0 and cu. ' Status ' = 0");

Sqlwhere.append ("and CP. Teacherid = @0 ");//Current teacher

Sqlwhere.append ("and CP. term = @8 ");//Current Semester

Course Name

if (coursepackid>0)

Sqlwhere.append ("and cp.id [email protected]");

Course Modules

if (unitid>0)

Sqlwhere.append ("and cu.id [email protected]");

Whether to share (-1: All, 0: not shared, 1: Shared)

if (IsPublic >=0)

Sqlwhere.append ("and pp. IsPublic = @3 ");

Release date

Sqlwhere.append ("and pp. Releasetime between @4 and @5 ");

Sqlorder= "ORDER by pp. Releasetime DESC ";

sql = sqlselect + sqlfrom + sqlwhere.tostring () + Sqlorder + "Limit @6,@7";

SqlCount = @ "SELECT count (pp.id)" +sqlfrom+sqlwhere.tostring ();

int pagestart = (pageIndex-1) * pageSize;

list<preparationmodel> list = _content. findpage<preparationmodel> (SQL, SqlCount, PageIndex, pageSize, out TotalCount, Teacherid, Coursepackid, Unitid, IsPublic, Publishdatestart, Publishdateend, Pagestart, Pagesize,termid);

return list;

List condition Paging query

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.