public void celulasN(List <Celula> list, string path) { String stringConexion = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path; using (OleDbConnection connection = new OleDbConnection(stringConexion)) { connection.Open(); OleDbDataReader reader = null; OleDbCommand command = new OleDbCommand("select * FROM CELULAS", connection); reader = command.ExecuteReader(); Celula aux; while (reader.Read()) { aux = new Celula(); aux.claveCelula = int.Parse(reader["cveCelula"].ToString()); aux.nombreCelula = reader["nomCelula"].ToString(); aux.Ncelula = int.Parse(reader["numCelula"].ToString()); list.Add(aux); } reader.Close(); connection.Close(); } }
private void button1_Click(object sender, EventArgs e) { OleDbConnection connection; List <Promotor> auxProm = new List <Promotor>(); String stringConexion = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path; using (connection = new OleDbConnection(stringConexion)) { connection.Open(); OleDbCommand command = new OleDbCommand("UPDATE CELULAS SET nomCelula = '" + textBox1.Text + "', numCelula = " + textBox2.Text + " Where cveCelula = " + comboBox1.Text); command.Connection = connection; if (connection.State != ConnectionState.Open) { connection.Open(); } try { command.ExecuteNonQuery(); MessageBox.Show("Data Update"); Celula nuevo = new Celula(); nuevo.claveCelula = int.Parse(comboBox1.Text); nuevo.nombreCelula = textBox1.Text; nuevo.Ncelula = int.Parse(textBox2.Text); int aux = 0; foreach (Celula i in celulas) { if (i.claveCelula == int.Parse(comboBox1.Text)) { aux = celulas.IndexOf(i); } } celulas.RemoveAt(aux); celulas.Add(nuevo); connection.Close(); } catch (OleDbException ex) { MessageBox.Show("error al agregar en la BD"); Console.WriteLine(ex); connection.Close(); } } foreach (Promotor i in promotores) { if (i.estrategia == int.Parse(comboBox1.Text)) { stringConexion = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pathA; using (connection = new OleDbConnection(stringConexion)) { connection.Open(); OleDbCommand command = new OleDbCommand("UPDATE Promotores SET Celula = '" + textBox1.Text + "', Ncelula = " + textBox2.Text + " Where Cve_prom = " + i.clavePromotor); command.Connection = connection; if (connection.State != ConnectionState.Open) { connection.Open(); } try { command.ExecuteNonQuery(); ///MessageBox.Show("Data Update"); Promotor nuevo = new Promotor(); nuevo = i; nuevo.celula = textBox1.Text; nuevo.Ncelula = int.Parse(textBox2.Text); auxProm.Add(nuevo); connection.Close(); } catch (OleDbException ex) { MessageBox.Show("error al agregar en la BD"); Console.WriteLine(ex); connection.Close(); } } } else { auxProm.Add(i); } } promotores.Clear(); promotores = auxProm; }