Pass table as parameter to SQLCLR
Tell me answer
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajeev PunhaniRank #551 · 4.4K reputationPosted Feb 6, 2016, 1:25 AM EST
Amit Kumar SinghRank #562 · 4.3K reputationPosted Feb 6, 2016, 2:03 AM EST
Guest User34 reputationPosted Feb 6, 2016, 2:10 AM EST
Hima BinduRank #4,292 · 353 reputationPosted Jul 18, 2016, 10:25 PM EDT
This is how you pass TVP as input parameter this ex is using Data Reader
// create data table to insert items
_dt = new DataTable("Items");
_dt.Columns.Add("ItemID", typeof(string));
_dt.Columns.Add("Name", typeof(string));
_dt.Rows.Add(4, "SuperBowl 9 Hat");
_dt.Rows.Add(5, "SuperBowl 10 T-Shirt");
_dt.Rows.Add(6, "SuperBowl 13 Towel");
_dt.Rows.Add(7, "SuperBowl 14 Helmet");
SqlConnection con; // modify connection string to connect to your database string conStr = "Server=localhost;Database=MSSQLTIPS;Trusted_Connection=True;"; con = new SqlConnection(conStr); con.Open(); using (con) { // Configure the SqlCommand and SqlParameter. SqlCommand sqlCmd = new SqlCommand("dbo.InsertItemsTVP", con); sqlCmd.CommandType = CommandType.StoredProcedure; SqlParameter tvpParam = sqlCmd.Parameters.AddWithValue("@ItemTVP", _dt); //Needed TVP tvpParam.SqlDbType = SqlDbType.Structured; //tells ADO.NET we are passing TVP sqlCmd.ExecuteNonQuery(); } con.Close();Guest User34 reputationPosted Jul 18, 2016, 11:05 PM EDT