如何在VB.NET中使用输出参数执行SQL存储过程? [英] How to Execute SQL Stored Procedure with Output Parameters in VB.NET ?

查看:231
本文介绍了如何在VB.NET中使用输出参数执行SQL存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



我在使用SQL Server 2008的VB.NET 2010中工作。



我使用SQL Server 2008管理工作室在我的数据库中创建了一个带有输出参数的存储过程

这样...



创建过程sp_InventoryAnalysis_M(



@RecordNoItem INT,

@ItemName NVarChar(200)Out,

@NetStock Money Out



As

开始



选择

@ ItemName = tbl_Items.ItemName

来自

tbl_Items

其中

tbl_Items.RecordNoItem =@RecordNoItem < br $>
订购商品

tbl_Items.RecordNoItem



选择

@ NetStock = SUM( tbl_Stock.ItemIn)-SUM(tbl_Stock.ItemOut)

来自

tbl_Stock

其中

tbl_Stock.RecordNoCompany = @RecordNoItem

结束



现在我正在尝试在sql server management st中执行此过程像这样的udio ......



执行sp_InventoryAnalysis_M 15



但是它给了我以下错误.. 。



Hello to All !

I m working in VB.NET 2010 with SQL Server 2008.

I created a Stored Procedure with output parameter in my Database using SQL Server 2008 Management Studio
Like this ...

Create PROCEDURE sp_InventoryAnalysis_M(

@RecordNoItem INT,
@ItemName NVarChar(200) Out,
@NetStock Money Out
)
As
Begin

Select
@ItemName=tbl_Items.ItemName
From
tbl_Items
Where
tbl_Items.RecordNoItem=@RecordNoItem
Order By
tbl_Items.RecordNoItem

Select
@NetStock=SUM(tbl_Stock.ItemIn)-SUM(tbl_Stock.ItemOut)
From
tbl_Stock
Where
tbl_Stock.RecordNoCompany=@RecordNoItem
End

now i am trying to execute this procedure in sql server management studio like this ...

Execute sp_InventoryAnalysis_M 15

but it gives me the following error ...

Msg 201, Level 16, State 4, Procedure sp_InventoryAnalysis_M, Line 0
Procedure or function 'sp_InventoryAnalysis_M' expects parameter '@ItemName', which was not supplied.





任何人都可以识别我犯错误的地方吗?



第二个问题是我想在我的VB.NET应用程序中执行此过程并从其输出参数中获取值并使用将其分配给变量。



谢谢。



can anyone identify where i made mistake ?

The second question is this i want to execute this procedure in my VB.NET application and get value from its output parameter and use assign it into a variable.

Thanks.

推荐答案

你需要声明输出参数并将它们作为参数传递



http:// stackoverflow。 com / questions / 1589466 / execute-stored-procedure-with-an-output-parameter [ ^ ]



从你的代码中调用它



ADO.NET - 如何使用输出参数调用存储过程? [ ^ ]
You need to declare the output parameters and pass them in as params

http://stackoverflow.com/questions/1589466/execute-stored-procedure-with-an-output-parameter[^]

To call it from your code

ADO.NET – How to call a stored procedure with output parameters?[^]


点击此链接:如何:使用存储过程执行查询以及输入和输出参数 [ ^ ]


这篇关于如何在VB.NET中使用输出参数执行SQL存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆