I have a stored procedure as follows
create procedure [dbo].[PriceConfirm]
@quote float,
@membershipType int,
@promocode nvarchar(20),
@giftCertificateCode nvarchar(20)
as
if(LEN(@giftCertificateCode)>1)
begin
declare @giftType int
select @giftType = MembershipType from GiftCertificate where GiftCertificateCode=@giftCertificateCode
if @giftType = @membershipType
begin
select 1 as result
end
else
begin
select 0 as result
end
end
else
begin
declare @total float
select @total = Price from MembershipType where TypeID=@membershipType
declare @discount float
select @discount = 0
if(LEN(@promocode)>1)
begin
select @discount = DiscountAmount from Membership_Promo where Promocode=@promocode and MembershipType = @membershipType
end
else
begin
select @discount=0
end
if ABS(@total-@discount-@quote) <.01
begin
select 1 as result
end
else
begin
select 0 as result
end
end
And if I just execute the stored procedure in SQL Server Management Studio, it works.
exec PriceConfirm @quote=69.99, @membershipType=6, @promocode='1', @giftCertificateCode='1'
That returns 1, as it should.
But in C#, when I try to pass in the parameters @quote, @membershipType, @promocode, @giftCertificateCode with the exact same values, I get an exception in the code. It reads '69.99' is out of range.
In my table and in the stored procedures, I have the columns as floats. I just don't understand why passing in a C# double is giving me a precision error. Can anybody advise?
Edit:
Here's the C# code:
IDataAccess dataAccess = _dataAccessService.GetDataAccess();
IDataConnection connection = _dataAccessService.GetConnection(Connectionstring);
var operation = new DataOperation("PriceConfirm");
operation.Parameters.Add(new DataParameter("@quote", DbType.Double, quote));
operation.Parameters.Add(new DataParameter("@membershipType", DbType.Int32, membership));
operation.Parameters.Add(new DataParameter("@promocode", DbType.String, promocode));
operation.Parameters.Add(new DataParameter("@giftCertificateCode", DbType.String, giftcode));
IResultSet reader = dataAccess.ExecuteResultSet(connection, operation, ResultSetType.Reader);
Reader is null after it tries to execute the operation. It throws an exception saying that "Data Parameter '69.99' is out of range."