dalebuchanan


Hi,

I execute this query in SQL Server 2005 Management Studio:

SELECT c.id, c.clientname
FROM NFClients AS c INNER JOIN
NFExportGroups AS eg ON eg.cid = c.id INNER JOIN
NFExportGroupInfo AS ei ON ei.exportid = eg.exportid
WHERE (ei.meterid = 4938) AND (NOT (eg.emailgroup IS NULL))

I get one row returned and it is correct.

Then I go to Visual Studio 2005, to my C-Sharp application, and I use the same query to populate two indexes of 'rowvalues', my trusty two-dimensional string array:

Code Snippet

SqlCommand sqlcmdExx = new SqlCommand("SELECT c.id, c.clientname from NFClients AS c INNER JOIN " +

"NFExportGroups AS eg ON eg.cid = c.id INNER JOIN NFExportGroupInfo AS ei ON ei.exportid = eg.exportid " +

"WHERE (ei.meterid = " + comparedgroupids[i, 2].ToString() + ") AND (NOT (eg.emailgroup IS NULL))", sqlconnBuildDataGridViewSet);

SqlDataReader sqldrExx = sqlcmdExx.ExecuteReader();

while (sqldrExx.Read())

{

rowvalues[i, 2] = sqldrExx.GetValue(1).ToString();

rowvalues[i, 3] = sqldrExx.GetValue(0).ToString();

}

sqldrExx.Close();

This time, the SqlDataReader picks up two rows, and the second one, with a different c.id and c.clientname does have a NULL value for eg.emailgroup. I have verified that the value of comparedgroupids[i, 2] is 4938, and I have also confirmed that sqlcmdExx.CommandText is exactly the same as the query I run in the SQL Server Management Studio. Why do I get different results with same query on the same database

Thanks.

Dale




Re: C# and SQL Server 2005, Same Query Different Results (More Rows)

Kingsonal


I'm not sure as to the cause of the difference but try using "(eg.mailgroup IS NOT NULL)" instead of (NOT (eg.emailgroup IS NULL))




Re: C# and SQL Server 2005, Same Query Different Results (More Rows)

dalebuchanan

Hi,

Found out this morning it was my mistake, I was looking at the wrong copy of the database. Sorry about that.

Dale