【发布时间】:2026-01-24 06:45:01
【问题描述】:
这是我的 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
这是数据库的样子:
我遇到了一个错误
输入的字符串格式不正确
我不知道出了什么问题,有什么想法吗?
【问题讨论】:
-
您能否详细说明您的实际问题?你面临什么问题?
-
您的代码发生了什么?会报错吗?
-
抱歉,我更新了我的问题。
Input string was not in a correct format.发生错误。
标签: c# sql database sql-server-2008 stored-procedures