开发者

SqlHelper.ExecuteReader Function that executes a stored procedure

开发者 https://www.devze.com 2023-01-16 11:40 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消