的我有一個存儲過程如下走出C#的誤差範圍,以SQL
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 [email protected]
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 [email protected]
declare @discount float
select @discount = 0
if(LEN(@promocode)>1)
begin
select @discount = DiscountAmount from Membership_Promo where [email protected] and MembershipType = @membershipType
end
else
begin
select @discount=0
end
if ABS(@[email protected]@quote) <.01
begin
select 1 as result
end
else
begin
select 0 as result
end
end
如果我只是在執行SQL Server Management Studio中的存儲過程,它的工作原理。
exec PriceConfirm @quote=69.99, @membershipType=6, @promocode='1', @giftCertificateCode='1'
返回1,因爲它應該。
但是在C#中,當我嘗試傳入具有完全相同值的參數@quote,@membershipType,@ promocode,@ giftCertificateCode時,代碼中出現異常。它讀取'69.99'超出範圍。
在我的表和存儲過程中,我有列作爲浮動。我只是不明白爲什麼傳入C#double會給我一個精確的錯誤。任何人都可以建議嗎?
編輯:
這裏的C#代碼:
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是空它試圖執行操作後。它會拋出一個異常,說「數據參數'69.99'超出範圍。」
您可以顯示設置呼叫參數的代碼嗎? – Fosco 2010-08-30 15:19:57
由於您的存儲過程在Sql Server中工作,請從C#解決方案發布調用代碼。錯誤可能在那裏,但很難找到它是否沒有發佈。 – AllenG 2010-08-30 15:19:59
@ rapier7您能否顯示您用來調用SP的代碼,請 – msarchet 2010-08-30 15:20:05