How to bulk insert a CSV file into SQLite C#
Posted
by Lirik
on Stack Overflow
See other posts from Stack Overflow
or by Lirik
Published on 2010-04-22T08:01:19Z
Indexed on
2010/04/22
10:33 UTC
Read the original article
Hit count: 1024
I have seen similar questions (1, 2), but none of them discuss how to insert CSV files into SQLite. About the only thing I could think of doing is to use a CSVDataAdapter
and fill the SQLiteDataSet
, then use the SQLiteDataSet
to update the tables in the database:
The only DataAdapter for CSV files I found is not actually available:
CSVDataAdapter CSVda = new CSVDataAdapter(@"c:\MyFile.csv");
CSVda.HasHeaderRow = true;
DataSet ds = new DataSet(); // <-- Use an SQLiteDataSet instead
CSVda.Fill(ds);
To write to a CSV file:
CSVDataAdapter CSVda = new CSVDataAdapter(@"c:\MyFile.csv");
bool InclHeader = true;
CSVda.Update(MyDataSet,"MyTable",InclHeader);
I found the above code @ http://devintelligence.com/2005/02/dataadapter-for-csv-files/
The CSVDataAdapter
was supposed to come with OpenNetCF's SDF, but it doesn't seem to be available anymore.
Does anybody know where I can get a CSVDataAdapter
? Perhaps somebody knows the much simpler thing: how to do bulk inserts of CSV files into SQLite... your help would be greatly appreciated!
© Stack Overflow or respective owner