title: Distinct Pagination with ROW_NUMBER() and Total Count in ASP.Net
body: <p>In Asp.net, I am trying to achieve pagination using following code:</p>
  
  <pre><code>String query="SELECT * "+
               "FROM (SELECT Distinct emp_name, emp_address, "+
               "         ROW_NUMBER() OVER(ORDER BY emp_id) AS rownum"+
               "       FROM Employee"+
               "     )as Person "+
               "WHERE rownum&gt;"+ start +" and rownum &lt;="+ end +";
  
  SqlCommand cmd = new SqlCommand(query, conn);
  conn.Open();
  
  SqlDataReader reader = cmd.ExecuteReader();
  </code></pre>
  
  <p>Above code does not retrieve <code>Distinct</code> rows.<br>
  How can I adjust my <code>query</code> to get <code>distinct</code> <strong>emp_name</strong> and <code>order by</code> <strong>emp_id</strong> along with total number of entries in single <code>ExecuteReader()</code>?  </p>
  
  <p>Currently I am calling <code>ExecuteReader()</code> twice first for data and and second for total count.   </p>
  
  <p>I followed <a href="https://stackoverflow.com/questions/8160694/sql-server-distinct-pagination-with-row-number-not-distinct">SQL Server DISTINCT pagination with ROW_NUMBER() not distinct</a> but was unable to understand how to implement it in my code. Please help.</p>