Note that there are some explanatory texts on larger screens.

plurals
  1. POOut of range error from C# to SQL
    primarykey
    data
    text
    <p>I have a stored procedure as follows</p> <pre><code>create procedure [dbo].[PriceConfirm] @quote float, @membershipType int, @promocode nvarchar(20), @giftCertificateCode nvarchar(20) as if(LEN(@giftCertificateCode)&gt;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)&gt;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) &lt;.01 begin select 1 as result end else begin select 0 as result end end </code></pre> <p>And if I just execute the stored procedure in SQL Server Management Studio, it works.</p> <pre><code>exec PriceConfirm @quote=69.99, @membershipType=6, @promocode='1', @giftCertificateCode='1' </code></pre> <p>That returns 1, as it should.</p> <p>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.</p> <p>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?</p> <p>Edit:</p> <p>Here's the C# code:</p> <pre><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); </code></pre> <p>Reader is null after it tries to execute the operation. It throws an exception saying that "Data Parameter '69.99' is out of range."</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload