在VB中执行具有多个返回的存储过程 [英] Excecuting a Stored procedure with multiple returns in VB
问题描述
嗨
我有一个繁琐的过程,需要一个整数字段作为输入,例如IDnumber
然后返回两个字段,例如Name和Position
如何在VB.net中执行该过程,然后将这两个返回值分别存储在变量中?
存储过程:
_______________________
spGetDetails @intID
---------
--------
-------
返回名称,位置
_________________________
这样的东西?
Hi
I Have a strored procedure that requires one integer field as input eg.IDnumber
and it then returns two fields eg.Name and Position
how will I work towards executing the procedure in VB.net and then storing both these return values in variables sepratly?
STORED PROCEDURE :
_______________________
spGetDetails @intID
---------
--------
-------
return Name,Position
_________________________
something like that?
Thank you in advance!
推荐答案
您可以为proc指定out参数,而不使用返回的表,或者选择名称,位置,然后读取表回来.
此处 [
You can specify out parameters to your proc, instead of using the returned table, or do select name, position and then read the table you get back.
Here[^] is how to write a proc with out params.
using (System.Data.SqlClient.SqlCommand command1 = new System.Data.SqlClient.SqlCommand())
{
command1.CommandType = CommandType.Text;
command1.Connection = sc1;
// DIRECTION :: Input
command1.CommandText = "select @MyParameter = Count(*) FROM [Purchasing].[ShipMethod]";
System.Data.SqlClient.SqlParameter paramter1 = command1.Parameters.Add("@MyParameter", SqlDbType.SmallInt);
paramter1.Direction = ParameterDirection.Output;
command1.ExecuteNonQuery();
//The following value is now 6, the number of records inside the table
int newValue = (int)paramter1.Value;
}
是如何在调用中添加输出参数的示例.
is an example of how to add output parameters to your call.
这篇关于在VB中执行具有多个返回的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!