2013-08-05 38 views
4

嗨我有這樣的SQL參數即時得到的口頭禪拆箱爲INT錯誤不能拆箱爲INT

returnValue = (int)cmdUpdateCreatedOn.Parameters["@intcount"].Value; 

返回值被聲明爲INT的returnValue = 0 和我的參數也被聲明爲int和它正在獲取已更新行的行數。 我試過不同的轉換語法似乎沒有工作。

MY SP是

ALTER Procedure [dbo].[UpdateStation] 
@intcount int output AS 
select StationaryName into #stname from Stationaries where Authorized = 0 
select * from #stname 
Update Stationaries Set Authorized = 1 where Authorized = 0 set @intcount = @@rowcount 
+6

看看調試器中的值。什麼是價值?它的類型是什麼?我的錢的價值要麼是可空的int,要麼實際上是null,但不管問題是什麼,解決這個問題都是微不足道的。 – Servy

+1

你得到了什麼*確切*錯誤? –

+0

在調試器中它的值是一個整數,它說,不能解除'cmdUpdateCreatedOn.Parameters [「@ intcount」]。Value'作爲int – CSharper

回答

8

我有同樣的問題。

在存儲過程中返回的INT類型爲「SHORT」。我不知道爲什麼。

無法轉換...「@ SubjectID」...(其實際類型爲'short')爲'string'。

解決方案:
1.拆箱C#中的 '短' 或
2.使用Convert.ToInt32在C#。