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 は次のようになります。
エラーが発生しました
入力文字列は、正しい形式ではありませんでした
何がうまくいかないのかわかりません。何かアイデアはありますか?