Note that there are some explanatory texts on larger screens.

plurals
  1. POSqlDataAdapter.Fill(DataTable) Returns No Rows
    primarykey
    data
    text
    <p>I am trying to use a SqlDataAdapter to fill a DataTable, which I use as a data source to a DataGrid. The query is fine, at least when I run it manually in SSMSE. When I do the fill operation, the table gets the right columns, but no rows. The most frustrating part of this is that the code is identical (with a different query) on a different page. I cannot post the query, but my initialization code looks like this:</p> <pre><code>SqlCommand areaDAC = new SqlCommand (areaQuery, connection); areaDAC.Parameters.Add (new SqlParameter ("@param", System.Data.SqlDbType.NVarChar, 50)); m_areaDataAdapter = new SqlDataAdapter (areaDAC); </code></pre> <p>Then to use it:</p> <pre><code>m_areaDataAdapter.SelectCommand.Parameters["@param"].Value = "Filter Val"; DataTable table = new DataTable (); m_areaDataAdapter.Fill (table); </code></pre> <p>At this point, table has the right number of columns and no rows. I know the parameters are being added correctly, I know that data exists for the given query.</p> <p><strong>Update</strong> (as provided by Nik in a comment):</p> <pre><code>SELECT * FROM (SELECT ROW_NUMBER() OVER(ORDER BY DateAndTime DESC) AS rowNum, areaName, stationName, lineName, DateAndTime, Element, Description FROM sdrReportArea, sdrReportStation, sdrReportTLine, SDRSequenceEvents, SDRSequenceStates WHERE sdrReportArea.areaID = sdrReportStation.stationID AND sdrReportStation.stationID = sdrReportTLine.stationID AND sdrReportTLine.lineID = SDRSequenceEvents.LineID AND SDRSequenceEvents.StateID = SDRSequenceStates.StateID AND DateAndTime &gt;= @startDate AND DateAndTime &lt;= @endDate AND areaName = @area) AS TempTbl WHERE rowNum BETWEEN @startRow AND @endRow; </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.
 

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