Inserting records into a table....


Author
Message
StarkMike
StarkMike
StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)
Group: Forum Members
Posts: 436, Visits: 944
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.
StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
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.
StarkMike
StarkMike
StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)
Group: Forum Members
Posts: 436, Visits: 944
Thanks for the suggestion Ben. I thought my way was pretty clever I just was curious if there was a better way. Smile
StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
It is very clever.  And bulk updates might not be for you Smile
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search