What’s the easiest way to import a CSV into a database via web application?
UPDATE:
Small example of CSV:
stop_id, stop_name, stop_desc, stop_lat, stop_lon, zone_id, stop_url
TR, Trenton, , 40.2177778, -74.7550000, 6,
LVTN, Levittown-Tullytown, , 40.1402778, -74.8169444, 5,
BRST, Bristol, , 40.1047222, -74.8547222, 4,
CROY, Croydon, , 40.0936111, -74.9066667, 4,
EDGT, Eddington, , 40.0830556, -74.9336111, 4,
CORN, Cornwells Heights, , 40.0716667, -74.9522222, 3,
TORR, Torresdale, , 40.0544444, -74.9844444, 3,
HOLM, Holmesburg Jct, , 40.0327778, -75.0236111, 2,
If you take the Portable and Efficient Generic Parser for Flat Files and create a new Visual C# Console application that has a reference to it, the following code will load the contents of a CSV file into a DataTable:
The next step would be to save the data in
datato your database server. This code assumes that the structure of the CSV file matches exactly that of a table calledTableNamein your database:You’d then want to add a call to
SaveDataToDatabasein yourMainmethod. I think there’s enough code here for you to tweak it to suit your purpose.