简体   繁体   中英

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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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