Jump to content

insert data into MySql from CSV file


shanerobinson

Recommended Posts

Hi Everyone,I need some help please! i have a simple MySql database setup and if i run the code below directly in the MySql query browser it works fine!load data local infile 'C:/Users/robinsons/Documents/data.csv' into table contactsfields terminated by ','enclosed by '"'lines terminated by '\n'(firstname, lastname, address1, address2, phone)This code is just importing the data from my CSV file and inserting it into my database.My question is does anybody have any code that i could run from an ASP page to do the exact same process as above?Thankyou...

Link to comment
Share on other sites

You can send those same commands in ASP. Using java script:

var dbcon = Server.CreateObject("ADODB.RecordSet");dbcon.ActiveConnection = "your connection string";var query = "load data local infile 'C:\\Users\\....' into table contacts\n";query += "fields terminated by ','\n";query += "enclosed by \"\"\n";query += .....dbcon.open(query);

That will load a local file on the server into the database like the code you have above. If you want to upload a file first and import that then that's another issue.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...