SqlHelper.ExecuteReader Function that executes a stored procedure
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, Sy开发者_JS百科stem.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
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.
精彩评论