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:
SqlCommand areaDAC = new SqlCommand (areaQuery, connection);
areaDAC.Parameters.Add (new SqlParameter ("@param",
System.Data.SqlDbType.NVarChar, 50));
m_areaDataAdapter = new SqlDataAdapter (areaDAC);
Then to use it:
m_areaDataAdapter.SelectCommand.Parameters["@param"].Value = "Filter Val";
DataTable table = new DataTable ();
m_areaDataAdapter.Fill (table);
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.
Update (as provided by Nik in a comment):
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 >= @startDate AND DateAndTime <= @endDate
AND areaName = @area) AS TempTbl
WHERE
rowNum BETWEEN @startRow AND @endRow;
1 Answer