简体   繁体   English

从C#将表类型传递给存储过程?

[英]Pass a Table Type to a Stored Proc from c#?

I've been using SQL Server 2008 for a while now, yet only today, found out you can create a Table type: 我已经使用SQL Server 2008一段时间了,但直到今天,才发现您可以创建Table类型:

CREATE type MyNewTableType as table {

And then pass it to a proc. 然后将其传递给proc。

However, can this functionality be used from within a .Net application (C# is my lang of choice...)? 但是,是否可以在.Net应用程序中使用此功能(C#是我的首选lang ...)? Is it possible to create something within my data access layer, and then pass it as a parameter to my stored procedure? 是否可以在我的数据访问层中创建某些东西,然后将其作为参数传递给我的存储过程?

Yes it can. 是的,它可以。 See the section Configuring a SqlParameter Example in the MSDN reference which will tell you to do something like the following: 请参阅MSDN参考中的“ 配置SqlParameter示例 ”部分,该部分将告诉您执行以下操作:

SqlParameter tvpParam = insertCommand.Parameters.AddWithValue(
    "@tvpNewCategories", addedCategories);
tvpParam.SqlDbType = SqlDbType.Structured;
tvpParam.TypeName = "dbo.CategoryTableType";

The two sections in the MSDN reference following this may also be helpful. 此之后的MSDN参考中的两个部分也可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM