如何在 C# 中将用户定义的表类型作为存储过程参数传递 [英] How to pass User Defined Table Type as Stored Procedured parameter in C#
本文介绍了如何在 C# 中将用户定义的表类型作为存储过程参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 SQL Server 2008 中,我们可以定义表类型并将其用作存储过程的参数.
In SQL Server 2008, we can define a table type and use it as a stored procedures' parameter.
但是我怎样才能在这个存储过程的 C# 调用中使用它呢?换句话说,如何使用 SQL Server 2008 的这个新特性创建一个表或列表并将其传递到 C# 代码中的存储过程中?
But how can I use it in C# invocation of this stored procedure? In other words, how to create a table or list and pass it into a stored procedure in C# code with this new feature of SQL Server 2008?
推荐答案
你需要看这个 代码项目示例.
SqlParameter param = cmd.Parameters.AddWithValue("@FileDetails", dt);
其中 dt 是数据表,并且@fileDetails 参数是 SQL 中的表类型:
where dt is a DataTable, and the @fileDetails parameter is a table type in SQL:
create type FileDetailsType as table
(
FileName varchar(50),
CreatedDate varchar(50),
Size decimal(18,0)
)
编辑:这篇 MSDN 开发人员指南文章 也会有所帮助.
这篇关于如何在 C# 中将用户定义的表类型作为存储过程参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文