Hi everybody! I've been trying to implement a CSV insert with a little trick: I use the OleDb CSV parser to fill my SQLiteDataSet, then I want to use the SQLiteDataSet to update the SQLite database. Unfortunately I've been stuck on this one problem- when I call Update on the SQLiteDataAdapter it always returns 0. For some reason the HasChanged() flag returns false too.
static void Main(string[ args)
{
SQLiteDatabase target = new SQLiteDatabase();
string csvFileName = "D:\\YahooTagsInfo.csv";
string tableName = "Tags";
target.InsertData(csvFileName, tableName);
Console.ReadKey();
}
public void InsertData(String csvFileName, String tableName)
{
String dir = Path.GetDirectoryName(csvFileName);
String name = Path.GetFileName(csvFileName);
using (OleDbConnection conn =
new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
dir + ";Extended Properties=""Text;HDR=Yes;FMT=Delimited\""))
{
using (OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM " + name, conn))
{
conn.Open();
QuoteDataSet ds = new QuoteDataSet();
adapter.Fill(ds, tableName);
Console.WriteLine("Num rows loaded is " + ds.Tags.Rows.Count);
InsertData(ds, tableName);
}
}
}
public void InsertData(QuoteDataSet data, String tableName)
{
using (SQLiteConnection conn = new SQLiteConnection(_connectionString))
{
conn.Open();
using (SQLiteDataAdapter sqliteAdapter = new SQLiteDataAdapter("SELECT * FROM " + tableName, conn))
{
using (sqliteAdapter.InsertCommand = new SQLiteCommandBuilder(sqliteAdapter).GetInsertCommand())
//using (sqliteAdapter.UpdateCommand = new SQLiteCommandBuilder(sqliteAdapter).GetUpdateCommand())
{
Console.WriteLine("Insert Command: " + sqliteAdapter.InsertCommand.CommandText);
Console.WriteLine("Param count: " + sqliteAdapter.InsertCommand.Parameters.Count);
/*
Console.WriteLine("Update Command: " + sqliteAdapter.UpdateCommand.CommandText);
Console.WriteLine("Param count: " + sqliteAdapter.UpdateCommand.Parameters.Count);
*/
Console.WriteLine("Has changes: " + data.HasChanges());
Console.WriteLine("Num rows updated is " +
sqliteAdapter.Update(data, tableName));
}
}
}
}
Here is the actual output:
Num rows loaded is 83
Insert Command: INSERT INTO [Tags] ([tagId], [tagName], [description], [colName]
, [dataType], [realTime]) VALUES (@param1, @param2, @param3, @param4, @param5, @
param6)
Param count: 6
Has changes: False
Num rows updated is 0
Could anybody help me figure out what's wrong here?
Here is a pastie link with my SQLiteDataSet (data) in xml format.