I am writing a .NET application that writes data to SQL Server 2008r2. I have two options for inserting the data, either I can create a large string insert statement, and send it as a text command, or I can collect the data in a .NET DataTable, and pass it as a table valued parameter. What are the benefits and costs of each method?
(I am omitting a good deal of code since I am just asking about the relative benefits, not the specific syntax)
e.g.:
Option 1:
string insert = @"insert into MyTable (id, val) values ( 1, 'a'),(2,'b'),(3,'c'),(4,'d');" Option 2:
DataTable dt = new DataTable(); dt.Columns.Add("id", typeof(int)); dt.Columns.Add("val", typeof(string)); .... create procedure uspMyProc @tt ttMyTableType readonly as begin insert into TestTable1 (id, strValue) select myId, myVal from @tt; end" Thanks for any help.