|
-
Aug 19th, 2008, 08:27 AM
#1
[2008] Inserting/updating multiple rows into a database's table
I was curious, how do other people insert/update multiple rows into a database's table?
If I got a loop and I'm enumerating some list that I need to push multiple Insert/Update commands to a database, in the past I've directly embedded values into SQL and run them as a single command:
Code:
Dim strSQL As String = String.Empty
For Each s As String In strList
strSQL &= String.Format("INSERT INTO MyTable (ID, Name) VALUES ('{0}', '{1}'); ", strID, s)
Next
Dim cmd As New MySql.Data.MySqlClient.MySqlCommand(strSQL, con)
cmd.ExecuteNonQuery()
Though it's easy, I don't like doing this for obvious reasons (single quotes come to mind) and would rather use parameters, but then I'd have to make a parameter for every line.
I could use multiple Command objects, but this would be extremely slow if I have a substantial amount of data to insert and I'd be inserting them one-by-one. I suppose I could use a DataAdapter, but building and pushing updates to DataAdapters always seems like a major pain in the rear (especially if I have a lot of fields)
How do you guys do it in this situation? Is there some trick I'm missing for pushing multiple inserts/updates? Should I just make a DataTable + DataAdapter and push multiple updates/inserts that way?
Last edited by Jenner; Aug 19th, 2008 at 08:46 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|