2013-04-13 22 views
-2

我創建了一個存儲過程,並從Visual Studio調用它,但是當我調用存儲過程時,該程序有一個編譯器錯誤。存儲過程確實存在於SQL Server中。調用SQL Server存儲過程的問題

這是錯誤:

no overload "sumtotal" for method takes 0 argument

在SQL Server

存儲過程:

CREATE PROCEDURE sumtotal(@totaling int output) 
AS 
BEGIN 
declare @sum int 
set @sum=(select SUM(amount_income) from IncomeTable) 
insert into Total_Table(Total_Income) 
values(@sum) 
    set @[email protected] 
    return @totaling 
END 
GO 
在VS

AccountDBClassDataContext context = new AccountDBClassDataContext(); 
int total; 

private void button3_Click(object sender, EventArgs e) 
{ 
    dataIncome = context.sumtotal(); 
} 

我知道也許我的問題是愚蠢的問題,但是這是一個題。

請幫幫我。

乾杯。

回答

3

有一個在存儲過程中指定一個output參數,所以你必須通過它,當你調用它:

private void button3_Click(object sender, EventArgs e) 
{ 
    int? dataIncome = null; 
    context.sumtotal(ref dataIncome); 
} 
+0

感謝快速回復。我寫「context.sumtotal(out dataIncome);」但是當我運行時,程序有錯誤。 'Accountant_App.AccountDBClassDataContext.sumtotal(ref int?)'的最佳重載方法匹配有一些無效參數,並且參數1:不能從'out int'轉換爲'ref int?' 。爲什麼?我該怎麼辦? –

+0

謝謝。但爲什麼我應該使用int? ?和int有什麼區別?和int?當我創建一個str prc並且當我調用這個時,我應該使用'ref'變量與'int?'類型?我寫這個,但程序有錯誤:使用未分配的局部變量'dataa' –

+0

'int?'實際上轉換爲'Nullable ',並且必須使用它,因爲您的SP無法返回任何值。不同的是,'int?'可以設置爲'null',而標準'int'不能。 – MarcinJuraszek