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.
精彩评论