Here is my code in C#:
float r_discountValue = 0;
SqlConnection con = Constant.GetConnection();
SqlCommand cmd = new SqlCommand("Coupon_GetDiscountFromValidCouponCode", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters["@PKCouponCode"].Value = "DIS_77";
SqlDataReader reader = cmd.ExecuteReader();
r_discountValue = float.Parse(reader.ToString());
ALTER PROCEDURE [dbo].[Coupon_GetDiscountFromValidCouponCode]
WHERE CouponCode = @PKCouponCode AND Valid = 1
Input string was not in a correct format
If you want the discount value, then you should return only the discount from the SP (since it is named
SELECT CouponDiscount FROM Coupon WHERE CouponCode = @PKCouponCode AND Valid = 1
This will make it a one-column resultset, which matches the access
reader from C#.
The other option is of course to change the C# side to read the second item (index 1) or reference the column by name, e.g.
r_discountValue = float.Parse(reader.ToString()); r_discountValue = float.Parse(reader["CouponDiscount"].ToString());
You would have got
Input string was not in a correct format. because it was reading "DIS_77" which
float.parse cannot process.