Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have <strong>2 options</strong>:</p> <h2>Option 1</h2> <p><em>Create a new Stored Procedure</em> in your database as follows:</p> <pre><code>USE [YourDatabaseName] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE RelatedSchemaName.StoredProcedureName @bintStartingRowNumber bigint, @bintRowLength bigint AS BEGIN SET NOCOUNT OFF; WITH AllRows AS ( SELECT ROW_NUMBER() OVER (ORDER BY QID, DESC) AS RowNumber, * FROM Questions AS Q ) SELECT QID, Question, Opt1, Opt2, Opt3, Opt4, AnsOp, Marks FROM AllRows WHERE RowNumber BETWEEN @bintStartingRowNumber AND @bintStartingRowNumber + @bintRowLength ORDER BY QID, DESC END GO </code></pre> <p>Now, Add it in your project and then, change the following code lines:</p> <pre><code>if (page == 1) { cmd2 = new OleDbCommand("Select TOP " + PageSize + " QID,Question,Opt1,Opt2,Opt3,Opt4,AnsOp,Marks from Questions ORDER BY QID DESC", con); // CurrentPageIndex++; } else { int PreviouspageLimit = (page - 1) * PageSize; cmd2 = new OleDbCommand("Select TOP " + PageSize + " QID,Question,Opt1,Opt2,Opt3,Opt4,AnsOp,Marks from Questions " + "WHERE QID NOT IN " + "(Select TOP " + PreviouspageLimit + " QID from Questions ORDER BY QID DESC) ", con); // + //"order by MedicalClgID", con); } </code></pre> <p>with this:</p> <pre><code>int intFirstRowNumber = (page - 1) * PageSize; cmd2 = new SqlCommand(StoredProcedureName); cmd2.CommandType = CommandType.StoredProcedure; cmd2.Parameters.Add("@bintStartingRowNumber", SqlDbType.BigInt).Value = intFirstRowNumber; cmd2.Parameters.Add("@bintRowLength", SqlDbType.BigInt).Value = PageSize; </code></pre> <h2>Option 2</h2> <p>Change the following code lines:</p> <pre><code>if (page == 1) { cmd2 = new OleDbCommand("Select TOP " + PageSize + " QID,Question,Opt1,Opt2,Opt3,Opt4,AnsOp,Marks from Questions ORDER BY QID DESC", con); // CurrentPageIndex++; } else { int PreviouspageLimit = (page - 1) * PageSize; cmd2 = new OleDbCommand("Select TOP " + PageSize + " QID,Question,Opt1,Opt2,Opt3,Opt4,AnsOp,Marks from Questions " + "WHERE QID NOT IN " + "(Select TOP " + PreviouspageLimit + " QID from Questions ORDER BY QID DESC) ", con); // + //"order by MedicalClgID", con); } </code></pre> <p>with this:</p> <pre><code>int intFirstRowNumber = (page - 1) * PageSize; cmd2 = new OleDbCommand( "WITH AllRows AS (" + "SELECT ROW_NUMBER() OVER (ORDER BY QID, DESC) AS RowNumber, * " + "FROM Questions AS Q) " + "SELECT QID, Question, Opt1, Opt2, Opt3, Opt4, AnsOp, Marks " + "FROM AllRows " + "WHERE RowNumber BETWEEN " + intFirstRowNumber + " AND " + (intFirstRowNumber + PageSize) + " ORDER BY QID, DESC", con); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload