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);
}
// TODO: pass dt
}
And I have a stored procedure
CREATE PROCEDURE [dbo].[Admin_Fill]
-- Add the parameters for the stored procedure here
@MetricId INT,
@Descr VARCHAR(100),
@EntryDE VARCHAR(20)
What I want is to pass the datatable to this stored procedure, how?
You can use a Table Valued Parameter as of SQL Server 2008 / .NET 3.5….
Check out the guide on MSDN
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)