private void button1_Click(object sender, EventArgs e) { listView1.Items.Clear(); Tree new_tree = new Tree(adapter); new_tree.build(); if (new_tree.monitorsCount() > 0) { displayMonitors(new_tree); trees.Add(adapter.getPortName(), new_tree); button2.Enabled = true; //Upload monitors from the new tree to the DB db_connection.OpenConnection(); db_connection.uploadMonitors(new_tree); //db_connection.testQuery(); db_connection.CloseConnection(); } }
public bool uploadMonitors(Tree tree) { string query_start = "INSERT IGNORE INTO " + monitors_table + " (OWD_ID) VALUES "; MySqlCommand cmd = new MySqlCommand(); cmd.Connection = connection; if (tree.monitorsCount() > 100) { int i = 0; while (i < tree.monitorsCount()) { string query = query_start; query += tree.getMonitorsAsString(100, i); cmd.CommandText = query; cmd.ExecuteNonQuery(); i += 100; } } else { string query = query_start; query += tree.getMonitorsAsString(0); Debug.Write(query); cmd.CommandText = query; cmd.ExecuteNonQuery(); } try { return true; } catch (MySqlException ex) { Debug.WriteLine(ex); return false; } }