tags:

views:

40

answers:

1

Hello,

I am messing up somewhere when writing a function to execute stored procedure. I think i don't have an idea how to execute SqlHelper.ExecuteReader. in SQL server 2005

This should return the state name. But i get it empty. Any idea, why??

Thanks in advance :)

reader = SqlHelper.ExecuteReader(DbConnString, System.Data.CommandType.StoredProcedure, "GetStateName", parameters);
while (reader.Read())
    StateName = reader["StateName"].ToString();
return StateName;

and the stored proc:

Create PROCEDURE [dbo].[GetStateName](
@StateInitials varchar
)

AS 

Begin

SELECT StateName FROM StateList WHERE StateInitials=@StateInitials

End
A: 

I'd guess that the value you're passing to the SP for @StateInitials has more than one character, but because you've not specified the size of the varchar parameter (eg, varchar(25)), the value is being truncated to just one character, and therefore there are no matches.

See here

When n is not specified in a data definition or variable declaration statement, the default length is 1.

CodeByMoonlight