StrataFrame Forum

Inserting records into a table....

http://forum.strataframe.net/Topic5816.aspx

By StarkMike - 1/15/2007

I'm importing data from a CSV file. I am reading the file in using TextFieldParser and while I read it in I am building an INSERT sql statement on the fly. Here is what the SQL statement looks like:



INSERT INTO STITagsImport (TagNumber)

SELECT tbl.Expr1 FROM (

SELECT 'ATV0E0' AS Expr1 UNION ALL

SELECT 'ATV0E0' AS Expr1 UNION ALL

SELECT '1180849' AS Expr1 UNION ALL

SELECT 'END' AS Expr1

) AS tbl



The reason I am doing this is because I dont want to make four separate round trips to the database with four separate INSERT statements. I was just wondering if there was a better way.
By StrataFrame Team - 1/15/2007

Not without specifying the parameters explicitly.  And building the command dynamically.  You might also look at the SQL bulk update functionality... especially if you're updating more than just 4 rows.  System.Data.SqlClient.SqlBulkCopy is the object, I think.
By StarkMike - 1/15/2007

Thanks for the suggestion Ben. I thought my way was pretty clever I just was curious if there was a better way. Smile
By StrataFrame Team - 1/15/2007

It is very clever.  And bulk updates might not be for you Smile