如何给SQLSERVER存储过程传递数组参数
1个回答
展开全部
举例说明:
CREATE PROCEDURE dbo.DoSomethingWithEmployees
@List AS dbo.EmployeeList READONLY
AS
BEGIN
SET NOCOUNT ON;
SELECT EmployeeID FROM @List;
END
GO
在C#中的写法:
DataTable tvp = new DataTable();
using (conn)
{
SqlCommand cmd = new SqlCommand("dbo.DoSomethingWithEmployees", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter tvparam = cmd.Parameters.AddWithValue("@List", tvp);
tvparam.SqlDbType = SqlDbType.Structured;
// 执行存储过程,并获取结果
}
CREATE PROCEDURE dbo.DoSomethingWithEmployees
@List AS dbo.EmployeeList READONLY
AS
BEGIN
SET NOCOUNT ON;
SELECT EmployeeID FROM @List;
END
GO
在C#中的写法:
DataTable tvp = new DataTable();
using (conn)
{
SqlCommand cmd = new SqlCommand("dbo.DoSomethingWithEmployees", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter tvparam = cmd.Parameters.AddWithValue("@List", tvp);
tvparam.SqlDbType = SqlDbType.Structured;
// 执行存储过程,并获取结果
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询