Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found a solution to this problem from reading MSDN. The trick is to perform the full query and return only the interesting subset that way the sort is always consistent. The procedure,however, only works using SQL 2005.</p> <pre><code> [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select)] public static WordsCollection LoadForCriteria(string sqlCriteria, int maximumRows, int startRowIndex, string sortExpression) { //DEFAULT SORT EXPRESSION if (string.IsNullOrEmpty(sortExpression)) sortExpression = "OrderBy"; //CREATE THE DYNAMIC SQL TO LOAD OBJECT StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT "); selectQuery.Append(Words.GetColumnNames(string.Empty)); selectQuery.Append(" FROM ("); selectQuery.Append("SELECT "); selectQuery.Append(Words.GetColumnNames(string.Empty)); selectQuery.Append(", ROW_NUMBER() OVER (ORDER BY " + sortExpression + ") AS RowRank"); selectQuery.Append(" FROM sw_Words) AS WordsWithRowNumbers"); selectQuery.Append(" WHERE RowRank &gt;" + startRowIndex.ToString() + " AND " + "RowRank &lt;=" + (startRowIndex + maximumRows).ToString()); string whereClause = string.IsNullOrEmpty(sqlCriteria) ? string.Empty : " AND " + sqlCriteria; selectQuery.Append(whereClause); Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()); //EXECUTE THE COMMAND WordsCollection results = new WordsCollection(); int rowCount = 0; using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read()) { Words varWords = new Words(); Words.LoadDataReader(varWords, dr); results.Add(varWords); rowCount++; } dr.Close(); } return results; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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