You can pull down the inserted records in the form of a Table-Valued Parameter, like this:
Create a table type for the passed parameter:
CREATE TYPE dbo.CategoryTableType AS TABLE ( CategoryID int, CategoryName nvarchar(50) )
And pass a parameter from C # in the form DataTable , IEnumerable<SqlDataRecord> , or DbDataReader :
string sqlInsert = @"INSERT INTO dbo.Categories (CategoryID, CategoryName) SELECT nc.CategoryID, nc.CategoryName FROM @tvpNewCategories AS nc"; SqlCommand insertCommand = new SqlCommand(sqlInsert, connection); SqlParameter tvpParam = insertCommand.Parameters.AddWithValue("@tvpNewCategories", addedCategories); tvpParam.SqlDbType = SqlDbType.Structured; tvpParam.TypeName = "dbo.CategoryTableType";
A full example is in MSDN: Table-Valued Parameters
If there is a lot of data (more than 1000 lines), it is better to insert data through a push through bulk insert, by calling SqlBulkCopy.WriteToServer .