Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Well, you could just move the loops:</p> <pre><code>using (SQLiteTransaction trans = DataAccess.ConnectionManager.BeginTransaction()) { foreach (var week in weekList) { foreach (var day in week.Days) { foreach (var period in day.Periods) { using (SQLiteCommand com = new SQLiteCommand(...)) { com.Parameters.Add(new SQLiteParameter(...)); com.Parameters.Add(new SQLiteParameter(...)); com.Parameters.Add(new SQLiteParameter(...)); com.CommandText = "Insert into ..."; com.ExecuteNonQuery(); } } } } trans.Commit(); } </code></pre> <p>However, that seems a little ugly to me. I don't know how the SQLite provider will behave, but I think it would be at least worth <em>trying</em> to create the <code>SQLiteCommand</code> as per your original code, adding the parameters <em>but not their values</em>... and then moving the <code>ExecuteNonQuery</code> code into the innermost foreach loop. Something like this:</p> <pre><code>using (SQLiteTransaction trans = DataAccess.ConnectionManager.BeginTransaction()) { using (SQLiteCommand com = new SQLiteCommand(DataAccess.ConnectionManager)) { com.CommandText = "Insert into ..."; SQLiteParameter p1 = com.Parameters.Add(new SQLiteParameter(...)); SQLiteParameter p2 = com.Parameters.Add(new SQLiteParameter(...)); SQLiteParameter p3 = com.Parameters.Add(new SQLiteParameter(...)); foreach (var week in weekList) { p1.Value = week; foreach (var day in week.Days) { p2.Value = day; foreach (var period in day.Periods) { p3.Value = period; com.ExecuteNonQuery(); } } } } trans.Commit(); } </code></pre> <p>Just to reiterate, I don't know if that will work - but I'd <em>hope</em> it would.</p>
 

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