数据表传递到存储过程存储过程、数据表

2023-09-03 02:08:14 作者:鸽屿

我在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....

查看 MSDN

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)

 
精彩推荐