I would guess either, they are not the same, probably one of the compare literals is different or the loop logic is wrong.
Different record returned from SQL Server Management Studio and a C# ExecuteReader with the same exact query?
I am using the EXACT same query in SQL Server Management Studio (2014) as I am in my C# program, but I get different results. How is this possible?
My Query:
SELECT tblWTHistory.Date, tblWTHistory.EstCompDate, tblOperator.BadgeID, tblOperator.OperatorName, tblWTHistory.WONum, tblWTHistory.WOType, tblWTHistory.PartNum, tblWTHistory.CellReceivedQty, tblWTHistory.OpNum,
tblWorkCenter.WorkCenterName, tblWorkType.WorkTypeName, tblWTHistory.WorkQty, tblWTStatus.StatusName, tblWTHistory.ReasonID, tblWTReasons.ReasonName, tblWTHistory.Rework, tblWTHistory.OpComment
FROM tblWTHistory INNER JOIN
tblWTReasons ON tblWTHistory.ReasonID = tblWTReasons.ReasonID INNER JOIN
tblWTStatus ON tblWTHistory.StatusID = tblWTStatus.StatusID INNER JOIN
tblWorkType ON tblWTHistory.WorkTypeID = tblWorkType.WorkTypeID INNER JOIN
tblWorkCenter ON tblWTHistory.WorkCenterID = tblWorkCenter.WorkCenterID INNER JOIN
tblOperator ON tblWTHistory.OperatorID = tblOperator.OperatorID
WHERE (tblWTHistory.CellReceivedQty > 0) AND (FORMAT(tblWTHistory.EstCompDate, 'yyyy-MM-dd') >= '2025-02-10') AND (FORMAT(tblWTHistory.EstCompDate, 'yyyy-MM-dd') <= '2025-02-13') AND (tblWTHistory.WOType = 'WO') AND
(tblWTHistory.WONum = '1858974')
ORDER BY tblWTHistory.PartNum, tblWTHistory.WONum, tblWTHistory.OpNum, tblWTHistory.StatusID, tblWTHistory.OperatorID, tblWTHistory.Date
C# Code:
string sSQL = "" Same query as above
SqlCommand myCmd = new SqlCommand(sSQL, myConnection);
SqlDataReader dr = myCmd.ExecuteReader();
When I loop through the dr I get 3 records while the "Results" pane in SSMS gives me the correct 4 records.
Anyone else ever run into a problem like this?