您可以在SQL中创建用户定义的表类型。然后,在存储过程中,接受类型(您用户定义的表类型)的参数,并将数据表作为其值传递给存储过程。
这是来自http://msdn.microsoft.com/zh-
cn/library/bb675163.aspx的一些示例:
在SQL中:
CREATE TYPE dbo.CategoryTableType AS TABLE ( CategoryID int, CategoryName nvarchar(50) )
然后:
// Assumes connection is an open SqlConnection object.using (connection){// Create a DataTable with the modified rows.DataTable addedCategories = CategoriesDataTable.GetChanges(DataRowState.Added);// Configure the SqlCommand and SqlParameter.SqlCommand insertCommand = new SqlCommand( "usp_InsertCategories", connection);insertCommand.CommandType = CommandType.StoredProcedure;SqlParameter tvpParam = insertCommand.Parameters.AddWithValue( "@tvpNewCategories", addedCategories);tvpParam.SqlDbType = SqlDbType.Structured;// Execute the command.insertCommand.ExecuteNonQuery();}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)