I'm having trouble with a segment of code where i wish to update the application SQLite database with some entries from a remote MySQL database. The code executes without errors but still does not reflect in the database. Please i need help figuring out what I'm missing out.
Below is the code segment:
#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[]>();
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);
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);
}
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
What I have tried:
[remove duplicate code]