简体   繁体   English

SQL Server:如何将数据表作为输入参数传递给存储过程?

[英]SQL Server: How to pass data table to a stored procedure as an input parameter?

I have a data table which is filled within my application with some values that user has entered them via an excel file. 我有一个数据表,该表在我的应用程序中填充了一些用户通过excel文件输入的值。 My Application targer .net framework is 2.0 and I can NOT change it to 3.0 or 3.5 in order to use LINQ feature. 我的应用程序targer .net框架是2.0,我不能将其更改为3.0或3.5以使用LINQ功能。

So, I have to send my data table values to a stored procedure and contribute them in a join operation. 因此,我必须将我的数据表值发送到存储过程并在连接操作中提供它们。

Is it a good solution or not? 这是一个好的解决方案吗? If yes, How can I send my Data table to Stored procedure as an input parameter? 如果是,我如何将我的数据表作为输入参数发送到存储过程?

Thank you 谢谢

By using table-valued parameters you can send data to the SQLServer stored procedure. 通过使用表值参数,您可以将数据发送到SQLServer存储过程。 This user-defined type represents the definition of a table structure and is compatible with SQLServer 2008 and next versions. 此用户定义类型表示表结构的定义,并与SQLServer 2008和下一版本兼容。

You can find example and more information referring to this msdn aritcle 您可以找到有关此msdn aritcle的示例和更多信息

Large Complex: For large complex data I'd probably get your data into a *.csv file (if it's not already that way in Excel), use .Net to BCP it into #temp tables, and then on that same connection call the proc and have the proc always know to look for the data in the #temp tables. 大型复杂:对于大型复杂数据,我可能会将您的数据转换为* .csv文件(如果在Excel中不是那样),请使用.Net将其BCP转换为#temp表,然后在同一个连接上调用proc并让proc始终知道在#temp表中查找数据。 BCP is the fasted way to get large chunks of data into SQLServer. BCP是将大量数据存入SQLServer的禁区方式。

Medium Size: If the size of the data is small then you could format it as XML and send that to the proc. 中等大小:如果数据的大小很小,那么您可以将其格式化为XML并将其发送到proc。 Here's a quick example using C# http://www.a2zdotnet.com/View.aspx?Id=107 以下是使用C# http://www.a2zdotnet.com/View.aspx?Id= 107的简单示例

Small Delimited: For small list type data you might be able to get away with sending it as comma delimited string of values. 小型定界:对于小型列表类型的数据,您可能可以将其作为逗号分隔的值字符串发送。 This is very handy when sending a list of ID's to a proc ( http://blog.logiclabz.com/sql-server/split-function-in-sql-server-to-break-comma-separated-strings-into-table.aspx ) 将ID列表发送到proc时非常方便( http://blog.logiclabz.com/sql-server/split-function-in-sql-server-to-break-comma-separated-strings-into- table.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在SQL Server 2008中使用表类型输入参数调用存储过程 - Calling stored procedure with table type input parameter in sql server 2008 将表名作为输入参数传递给SQL Server存储过程 - Passing table name as a input parameter to a SQL server stored procedure 使用输入参数执行SQL Server存储过程 - Execute SQL Server stored procedure with input parameter 如何将表变量传递给SQL-Server 2014中的存储过程 - How to pass the table variable to a stored procedure in SQL-Server 2014 在SQL Server 2008中执行时如何将值传递给存储过程中的数据表 - How to pass value to the data-table in the stored procedure while executing in SQL Server 2008 SQL Server 在存储过程中的动态 sql 中使用表值输入参数 - SQL Server using table valued input parameter in dynamic sql in a stored procedure sql server存储过程IN参数 - sql server stored procedure IN parameter 如何仅将时间参数传递给SQL Server中的存储过程 - How can I pass only time parameter to a stored procedure in SQL Server 如何将SELECT语句结果作为参数传递给SQL Server存储过程中的函数? - How to pass SELECT statement result as parameter to function in stored procedure in SQL Server? 如何将表中列的每个值传递到存储过程并将结果保存到SQL-Server中的表中 - How to pass each value of the column from a table to a stored procedure and save the result in a table in SQL-Server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM