Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Update</strong>:</p> <p>After reading your solution let me say that I am embarrased that I did not catch that. Enumerating rows to set rowstate to added will work.</p> <p>But let me give you a cleaner way to do that using adapter.AcceptChangesDuringFill.</p> <pre><code> using (OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM " + name, conn)) { // this is the proper way to transfer rows adapter.AcceptChangesDuringFill = false; QuoteDataSet ds = new QuoteDataSet(); adapter.Fill(ds, tableName); Console.WriteLine("Num rows loaded is " + ds.Tags.Rows.Count); InsertData(ds, tableName); } </code></pre> <hr> <p>This imports 83 rows:</p> <p>Program.cs</p> <pre><code>using System; using System.Data; using System.Data.SQLite; namespace SqliteCsv { internal class Program { private static void Main(string[] args) { // fill your dataset QuoteDataSet ds = new QuoteDataSet(); ds.ReadXml("data.xml", XmlReadMode.InferTypedSchema); // hack to flag each row as new as per lirik // OR just set .AcceptChangesDuringFill=false on adapter foreach (DataTable table in ds.Tables) { foreach (DataRow row in table.Rows) { row.SetAdded(); } } int insertedRows; using ( SQLiteConnection con = new SQLiteConnection(@"data source=C:\Projects\StackOverflowAnswers\SqliteCsv\SqliteCsv\Quotes.db")) { con.Open(); // clear table - you may not want this SQLiteCommand cmd = con.CreateCommand(); cmd.CommandText = "delete from Tags"; cmd.ExecuteNonQuery(); using (SQLiteTransaction txn = con.BeginTransaction()) { using (SQLiteDataAdapter dbAdapter = new SQLiteDataAdapter("select * from Tags", con)) { dbAdapter.InsertCommand = new SQLiteCommandBuilder(dbAdapter).GetInsertCommand(true); insertedRows = dbAdapter.Update(ds, "Tags"); } txn.Commit(); } } Console.WriteLine("Inserted {0} rows", insertedRows); Console.WriteLine("Press any key"); Console.ReadKey(); } } } </code></pre> <p><strong>Original Answer:</strong></p> <p>This is the source of the SQLiteDataAdapter ctor that ultimately gets called. Note that no command builder is employed. You need to explicitly set the InserCommand property on the SQLiteDataAdapter, perhaps by using a SQLiteCommandBuilder?</p> <pre><code>public SQLiteDataAdapter(string commandText, SQLiteConnection connection) { this.SelectCommand = new SQLiteCommand(commandText, connection); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload