这是我在C#代码:如何获得C#中存储过程的结果?
float r_discountValue = 0;
SqlConnection con = Constant.GetConnection();
SqlCommand cmd = new SqlCommand("Coupon_GetDiscountFromValidCouponCode", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@PKCouponCode", SqlDbType.VarChar);
cmd.Parameters["@PKCouponCode"].Value = "DIS_77";
try
{
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
if(reader.Read()){
r_discountValue = float.Parse(reader[0].ToString());
}
reader.Close();
}
catch(Exception exception)
{
throw exception;
}
finally{
con.Close();
}
return r_discountValue;
存储过程:
ALTER PROCEDURE [dbo].[Coupon_GetDiscountFromValidCouponCode]
@PKCouponCode varchar(50)
AS
SELECT *
FROM Coupon
WHERE CouponCode = @PKCouponCode AND Valid = 1
下面是DB的样子:
我遇到一个错误
输入字符串的不正确的格式
我不知道发生了什么事情是怎么了,什么想法?
你能详细说明你的实际问题吗?你面临什么问题? – Sachin 2013-04-24 02:20:40
你的代码发生了什么?它会给出错误吗? – RichardTheKiwi 2013-04-24 02:20:46
SorrY,我更新了我的问题。 '输入字符串格式不正确.'发生错误。 – DNB5brims 2013-04-24 02:22:59