有可能将数组从.NET C#传递给SQL函数。
提前致谢。
此致。
你能告诉我怎么样吗?
答案 0 :(得分:3)
使用SQL Server 2008,是的,使用table-valued parameters。使用SQL Server 2005,您必须将数据包装在XML中,并在T-SQL函数中使用XQuery对其进行分解。
注意:您只能将表值参数传递给存储过程 - 而不是传递给函数。
从链接:
// Configure the SqlCommand and table-valued parameter.
SqlCommand insertCommand = new SqlCommand(
"usp_InsertCategories", connection);
insertCommand.CommandType = CommandType.StoredProcedure;
SqlParameter tvpParam =
insertCommand.Parameters.AddWithValue(
"@tvpNewCategories", dataReader);
tvpParam.SqlDbType = SqlDbType.Structured;
答案 1 :(得分:0)
Erland Sommarskog有两篇关于如何在SQL Server 2000和2005中执行此操作的优秀文章:
http://www.sommarskog.se/arrays-in-sql-2005.html
http://www.sommarskog.se/arrays-in-sql-2000.html
但是使用SQL Server 2008和表值参数,它更好更容易,所以如果你在2008年,一定要使用TVP!
马克