Sqldatareader and rowcount

Posted by phenevo on Stack Overflow See other posts from Stack Overflow or by phenevo
Published on 2010-05-04T08:34:16Z Indexed on 2010/05/04 8:38 UTC
Read the original article Hit count: 504

Filed under:
|
|

Hi,

I have a query:

declare @Code nvarchar(100)
select @Code="BMW"
select name from NewCars where code=@Code
if @@rowcount = 0
Select name from OldCars where code=@Code

In Sql managment studio first part give me 0 resuklts, and second 1 one result, and that is ok, but in sqldatareader I use the same query ofcource without:

declare @Code nvarchar(100)
select @Code="BMW"

because I use:

cmd.Parameters.AddWithValue("@Code", "BMW");

And

using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { Name= reader["Name"].ToString(); } } else { throw new NotSupportedException("Lack of car with this Code"); } }

gives me zero result

© Stack Overflow or respective owner

Related posts about tsql

Related posts about sql-server-2005