public void DatosPromotorN(List <Promotor> list) { 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 PROMOTORES", connection); reader = command.ExecuteReader(); Promotor aux; while (reader.Read()) { aux = new Promotor(); aux.nombrePromotor = reader["nombre_promotor"].ToString(); aux.clavePromotor = int.Parse(reader["Cve_prom"].ToString()); aux.estrategia = int.Parse(reader["Estrategia"].ToString()); aux.celula = reader["Celula"].ToString(); aux.claveInter = reader["CLAVE_INTERBANCARIA"].ToString(); aux.banco = reader["Banco"].ToString(); aux.Ncelula = int.Parse(reader["Ncelula"].ToString()); list.Add(aux); } reader.Close(); connection.Close(); } }
private void button2_Click(object sender, EventArgs e) { OleDbConnection con;//Representa una conexión abierta a un origen de datos String stringConexion = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path; using (OleDbConnection connection = new OleDbConnection(stringConexion)) { connection.Open(); OleDbCommand command = new OleDbCommand("UPDATE Promotores SET nombre_promotor = '" + textBox1.Text + "', Estrategia = " + textBox3.Text + ", Celula = '" + textBox2.Text + "', CLAVE_INTERBANCARIA = '" + textBox5.Text + "', Banco = '" + textBox7.Text + "', Ncelula = " + textBox8.Text + " Where Cve_prom = " + comboBox1.Text); command.Connection = connection; if (connection.State != ConnectionState.Open) { connection.Open(); } try { command.ExecuteNonQuery(); MessageBox.Show("Data Update"); Promotor nuevo = new Promotor(); nuevo.clavePromotor = int.Parse(comboBox1.Text); nuevo.nombrePromotor = textBox1.Text; nuevo.celula = textBox2.Text; nuevo.estrategia = int.Parse(textBox3.Text); nuevo.claveInter = textBox5.Text; nuevo.banco = textBox7.Text; nuevo.Ncelula = int.Parse(textBox8.Text); int aux = 0; foreach (Promotor i in promotores) { if (i.clavePromotor == int.Parse(comboBox1.Text)) { aux = promotores.IndexOf(i); } } promotores.RemoveAt(aux); promotores.Add(nuevo); connection.Close(); } catch (OleDbException ex) { MessageBox.Show("error al agregar en la BD"); Console.WriteLine(ex); connection.Close(); } } }
private void button1_Click(object sender, EventArgs e) { OleDbConnection con;//Representa una conexión abierta a un origen de datos String stringConexion = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path; using (OleDbConnection connection = new OleDbConnection(stringConexion)) { connection.Open(); OleDbCommand command = new OleDbCommand("INSERT into Promotores (nombre_promotor, Cve_prom, Estrategia, Celula, CLAVE_INTERBANCARIA, Banco, Ncelula) VALUES " + "('" + textBox1.Text + "'," + comboBox1.Text + "," + textBox3.Text + "," + "'" + textBox2.Text + "'," + "'" + textBox5.Text + "'," + "'" + textBox7.Text + "'," + textBox8 + ")"); command.Connection = connection; if (connection.State != ConnectionState.Open) { connection.Open(); } try { command.ExecuteNonQuery(); MessageBox.Show("Data Added"); Promotor nuevo = new Promotor(); nuevo.clavePromotor = int.Parse(comboBox1.Text); nuevo.nombrePromotor = textBox1.Text; nuevo.celula = textBox2.Text; nuevo.estrategia = int.Parse(textBox3.Text); nuevo.claveInter = textBox5.Text; nuevo.banco = textBox7.Text; nuevo.Ncelula = int.Parse(textBox8.Text); promotores.Add(nuevo); connection.Close(); } catch (OleDbException ex) { MessageBox.Show("error al agregar en la BD"); Console.WriteLine(ex); 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; }