By Dylan Barber on
8/23/2011 2:29 PM
I have been working on a new web application and recently ran into an interesting situation where I wanted to add possibly hundreds of records from one data entry screen. In the past I have done this a few different ways:
Loop through set of data and add each row one by one.
Create some delimited string and create some SQL to parse it into a temp table.
Both of those methods work but have serious drawbacks.
Method one is very easy to program but all those insert statements cause a lot of traffic to and from the database, this can cause a lot of scaling issues. Method two works if you are only inserting one value at a time and that value is not complex like lots of text or image byte arrays.
A much easier method of doing this would be to create a table fill it with data and simply use a insert statement to select all records from the table into our datatable. Now with SQL 2008 we can pass Table Valued Parameters (TVP) to a stored procedure and use it just like any other table in the...