i'm amazed that mysql doesnt come with a bulk loader that can do this for you..
from here, find a code example that lets you read txt files. if the files are in CSV i recommend a free library called JHL_Tools.dll
read the text file in, line at a time to save resources. with each line, run a database query to insert the records.
You are strongly recommended to use parameterized queries. This board has covered the topic of parameterized queries many times so a brief search should turn up a good result. In short, a param query looks like this:
myOleDbCommand.CommandText = "INSERT INTO tblEmployee(name, age) VALUES (?, ?)"
the database compiles the statement knowing that the ? are variables. You then set parameter values in the .Parameters collection of the the myOleDbCommand and run the command.. change the values, run it again.
this is much better and more secure than building an sql string each time
-
note: i assumed youre using OLE, but if youre using a mysql driver, the command set might be different. for instance in ms access the statement looks like that above. A param query in oralce looks like:
"INSERT INTO tblEmployee(name, age) VALUES
in_name, :in_age)"
and in sql server looks like:
"INSERT INTO tblEmployee(name, age) VALUES (@in_name, @in_age)"
so mysql might use different syntax