如何批量插入CSV文件到SQLite C# [英] How to bulk insert a CSV file into SQLite C#
问题描述
我看到过类似的问题( 1 ,2 ),但没有人讨论如何将CSV文件插入SQLite。关于我唯一能想到的是使用 CSVDataAdapter
并填写 SQLiteDataSet
,然后使用 SQLiteDataSet
更新数据库中的表:
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:
我发现的CSV文件的唯一DataAdapter实际上不可用: p>
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);
要写入CSV文件:
CSVDataAdapter CSVda = new CSVDataAdapter(@"c:\MyFile.csv");
bool InclHeader = true;
CSVda.Update(MyDataSet,"MyTable",InclHeader);
我发现上述代码@ http://devintelligence.com/2005/02/dataadapter-for-csv-files/
CSVDataAdapter
应该附带 OpenNetCF的SDF ,但它似乎不再可用。
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.
有人知道我可以得到一个 CSVDataAdapter
?也许有人知道一个更简单的事情:如何批量插入CSV文件到SQLite ...您的帮助将非常感谢!
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!
推荐答案
请尝试此操作 - 从C#导入/导出CSV从C#代码
try this -Import/Export CSV from SQLite from C# code
这篇关于如何批量插入CSV文件到SQLite C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!