数据表传递到存储过程 [英] Passing datatable to a stored procedure
本文介绍了数据表传递到存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在C#中的数据表中创建的。
I have a datatable created in C#.
using (DataTable dt = new DataTable())
{
dt.Columns.Add("MetricId", typeof(int));
dt.Columns.Add("Descr", typeof(string));
dt.Columns.Add("EntryDE", typeof(int));
foreach (DataGridViewRow row in dgv.Rows)
{
dt.Rows.Add(row.Cells[1].Value, row.Cells[2].Value, row.Cells[0].Value);
}
// blah blah
}
和我有一个存储过程
CREATE PROCEDURE [dbo].[Admin_Fill]
-- Add the parameters for the stored procedure here
@MetricId INT,
@Descr VARCHAR(100),
@EntryDE VARCHAR(20)
我想是到DataTable传递给该存储过程,怎么样?
What I want is to pass the datatable to this stored procedure, how?
感谢。
推荐答案
您可以使用值参数作为SQL Server的表2008 / .NET 3.5 ....
You can use a Table Valued Parameter as of SQL Server 2008 / .NET 3.5....
Check out the guide on MSDN
此外,因为有其他选择,我有一个comparisonof传递多个值(单场),以一个存储过程的三种途径(的 TVP VS XML VS CSV )
Also, as there other options available, I have a comparisonof 3 approaches of passing multiple values (single field) to a sproc (TVP vs XML vs CSV)
这篇关于数据表传递到存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文