开发者

Pass a Table Type to a Stored Proc from c#?

开发者 https://www.devze.com 2023-02-15 11:01 出处:网络
I\'ve been using SQL Server 2008 for a while now, yet only today, found out you can create a Table type:

I've been using SQL Server 2008 for a while now, yet only today, found out you can create a Table type:

CREATE type MyNewTableType as table {

And then pass it to a proc.

However, can this 开发者_如何学运维functionality be used from within a .Net application (C# is my lang of choice...)? 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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消