База данных Sqlite не сохраняет вставленные данные
У меня возникли проблемы с сегментом кода, где я хочу обновить базу данных приложения SQLite некоторыми записями из удаленной базы данных MySQL. Код выполняется без ошибок, но все равно не отражается в базе данных. Пожалуйста, мне нужна помощь, чтобы понять, что я упускаю.
Ниже приведен фрагмент кода :
#region Offline Upload if (items_going_offline > 0) { update_progress.SafeInvoke(d => d.Visible = true); DialogResult result = MessageBox.Show("Host " + items_going_offline + " document(s) to OFFLINE", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { #region Incoming if (MySqlincoming_refNos.Count > 0) { foreach (string re in MySqlincoming_refNos) { path_offline.Clear(); path_online.Clear(); select_query_online = "select * from " + store.database() + "incoming where ref_no = @ref"; MySql_cmd = new MySqlCommand(select_query_online, online_con1); MySql_cmd.Parameters.AddWithValue("@ref", (string)re); Retry.retry.Do(() => store.openConnection("mysql", online_con1, con1), TimeSpan.FromSeconds(10), 5); DataSet dsI = new DataSet(); MySqlDataAdapter daI = new MySqlDataAdapter(MySql_cmd); daI.Fill(dsI); if (dsI.Tables[0].Rows.Count > 0) { refNo = (string)dsI.Tables[0].Rows[0][1]; subject = (string)dsI.Tables[0].Rows[0][2]; date = (DateTime)dsI.Tables[0].Rows[0][3]; senders = (string)dsI.Tables[0].Rows[0][4]; ; receiver = (string)dsI.Tables[0].Rows[0][5]; try { for (int a = 1; a < 21; a++) { if (dsI.Tables[0].Rows[0][5 + a] != DBNull.Value) { string f = (string)dsI.Tables[0].Rows[0][5 + a]; path_online.Add(f.Remove(0, 39)); } } } catch (Exception ex) { MessageBox.Show("Unable to read data\n" + ex.Message); } List<byte[]> downloadedFiles = new List<byte[]>(); //download the files store.downloadFile(store.FTP(), path_online, ref downloadedFiles); Retry.retry.Do(() => store.openConnection("sqlite", online_con1, con1), TimeSpan.FromSeconds(10), 5); using (SQLiteTransaction Sqlite_transaction = con1.BeginTransaction()) { try { insert_query_online = "insert into incoming (ref_no, subject, date, sender, receiver, page_1, page_2, page_3, page_4, page_5, page_6, page_7, page_8, page_9, page_10, page_11, page_12, page_13, page_14, page_15, page_16, page_17, page_18, page_19, page_20) values(@ref_no, @subject, @date, @sender, @receiver, @page_1, @page_2, @page_3, @page_4, @page_5, @page_6, @page_7, @page_8, @page_9, @page_10, @page_11, @page_12, @page_13, @page_14, @page_15, @page_16, @page_17, @page_18, @page_19, @page_20)"; Sqlite_cmd = new SQLiteCommand(insert_query_offline, con1); Sqlite_cmd.Parameters.AddWithValue("@ref_no", (string)refNo); Sqlite_cmd.Parameters.AddWithValue("@subject", (string)subject); Sqlite_cmd.Parameters.AddWithValue("@date", (DateTime)date); Sqlite_cmd.Parameters.AddWithValue("@sender", (string)senders); Sqlite_cmd.Parameters.AddWithValue("@receiver", (string)receiver); //make some pages = null for (int a = 0; a < 20; a++) { if(a < downloadedFiles.Count) Sqlite_cmd.Parameters.AddWithValue("@page_" + (a + 1) + "", (object)downloadedFiles[a]); else Sqlite_cmd.Parameters.AddWithValue("@page_" + (a + 1) + "", null); } //Retry.retry.Do(() => Sqlite_cmd.ExecuteNonQuery(), TimeSpan.FromSeconds(10), 5); Sqlite_cmd.ExecuteNonQuery(); Sqlite_transaction.Commit(); update_progress.SafeInvoke(d => d.Increment(1)); offlineCountdown--; } catch (Exception ex) { MessageBox.Show("Unable to UPDATE an Offline incoming item"); Sqlite_transaction.Rollback(); } } store.closeConnection("sqlite", online_con1, con1); } store.closeConnection("mysql", online_con1, con1); } } #endregion
Что я уже пробовал:
[удалить дубликат кода]