private void button1_Click(object sender, EventArgs e) { OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =\"C:\\Users\\******\\Desktop\\Personal.accdb\""; OleDbCommand cmd; string consultaSQL = "INSERT INTO InasistenciasJefatura (Legajo, Estado, Fecha, Cargo, Turno, Aviso) VALUES (@Legajo, @Estado, @Fecha, @Cargo, @Turno, @Aviso)"; cmd = new OleDbCommand(consultaSQL, conn); cmd.Connection = conn; try { conn.Open(); } catch (Exception excepcion) { Console.Write(excepcion.Message); Console.ReadLine(); } if (conn.State == ConnectionState.Open) { try { cmd.Parameters.AddWithValue("@Legajo", Convert.ToInt32(txtLeg.Text.ToString())); cmd.Parameters.AddWithValue("@Estado", txtEstado.Text.ToString()); cmd.Parameters.AddWithValue("@Fecha", Convert.ToDateTime(txtFecha.Text.ToString())); cmd.Parameters.AddWithValue("@Cargo", Cargo.Text.ToString()); cmd.Parameters.AddWithValue("@Turno", txtTurno.Text.ToString()); cmd.Parameters.AddWithValue("@Aviso", txtAviso.Text.ToString()); cmd.ExecuteNonQuery(); } catch (Exception excepcion) { Console.Write(excepcion.Message); Console.ReadLine(); } conn.Close(); } } }}
if (lector["Legajo"].ToString() == txtLeg.Text && txtLeg.Text.Substring(0,1)==3)
private void button1_Click(object sender, EventArgs e) { OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =\"C:\\Users\\*******\\Desktop\\Personal.accdb\""; OleDbCommand comando; OleDbCommand comando2; OleDbCommand comando3; OleDbDataReader lector; OleDbDataReader lector2; OleDbDataReader lector3; string consultaSQL = "SELECT Legajo , Estado , Fecha , Cargo , Turno , Aviso FROM InasistenciasJefatura"; string consultaSQL2 = "SELECT Legajo , Fecha , Estado , Hora , Aviso FROM InasistenciasBedel "; string consultaSQL3 = "SELECT Legajo , Fecha , Estado FROM InasistenciasSecretario "; comando = new OleDbCommand(consultaSQL, conn); comando2 = new OleDbCommand(consultaSQL2, conn); comando3 = new OleDbCommand(consultaSQL3, conn); try { conn.Open(); } catch (Exception excepcion) { Console.Write(excepcion.Message); Console.ReadLine(); } if (conn.State == ConnectionState.Open) { try { lector = comando.ExecuteReader(); lector2 = comando2.ExecuteReader(); lector3 = comando3.ExecuteReader(); while (lector.Read()) { txtMostrar.Text = "\n" + lector.GetValue(0).ToString(); txtMostrar.Text += " - " + lector.GetValue(1).ToString(); txtMostrar.Text += " - " + lector.GetValue(2).ToString(); txtMostrar.Text += " - " + lector.GetValue(3).ToString(); txtMostrar.Text += " - " + lector.GetValue(4).ToString(); txtMostrar.Text += " - " + lector.GetValue(5).ToString(); txtMostrar.Text += "\r\n---------------------------------------------------------------------"; } while (lector2.Read()) { txtMostrar.Text += "\r\n" + lector2.GetValue(0).ToString(); txtMostrar.Text += " - " + lector2.GetValue(1).ToString(); txtMostrar.Text += " - " + lector2.GetValue(2).ToString(); txtMostrar.Text += " - " + lector2.GetValue(3).ToString(); txtMostrar.Text += " - " + lector2.GetValue(4).ToString(); txtMostrar.Text += " - " + lector2.GetValue(5).ToString(); } while (lector3.Read()) { txtMostrar.Text += "\r\n" + lector3.GetValue(0).ToString(); txtMostrar.Text += " - " + lector3.GetValue(1).ToString(); txtMostrar.Text += " - " + lector3.GetValue(2).ToString(); } } catch (Exception excepcion) { Console.Write(excepcion.Message); Console.ReadLine(); } conn.Close(); } }
while (lector.Read()) { if (lector["Legajo"].ToString() == txtLeg.Text && txtLeg.Text.Substring(0, 1) == "6" || txtLeg.Text.Substring(0, 1) == "3") { //if (lector["Cargo"].ToString() == Cargo.Text.ToString()) cmd.Parameters.AddWithValue("@Legajo", Convert.ToInt32(txtLeg.Text.ToString())); cmd.Parameters.AddWithValue("@Estado", txtEstado.Text.ToString()); cmd.Parameters.AddWithValue("@Fecha", Convert.ToDateTime(txtFecha.Text.ToString())); cmd.Parameters.AddWithValue("@Cargo", Cargo.Text.ToString()); cmd.Parameters.AddWithValue("@Turno", txtTurno.Text.ToString()); cmd.Parameters.AddWithValue("@Aviso", txtAviso.Text.ToString()); cmd.ExecuteNonQuery(); } }
private void button1_Click(object sender, EventArgs e) { OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =\"C:\\Users\\AsusB85M-G\\Desktop\\Personal.accdb\""; OleDbCommand cmdA; OleDbCommand cmdB; OleDbDataReader lector; string consultaSQLA = "INSERT INTO InasistenciasJefatura (Legajo, Estado, Fecha, Cargo, Turno, Aviso) VALUES (@Legajo, @Estado, @Fecha, @Cargo, @Turno, @Aviso)"; string consultaSQLB = "SELECT Legajo,Cargo FROM Personal WHERE Legajo = @Legajo AND Cargo = @Cargo "; cmdA = new OleDbCommand(consultaSQLA, conn); cmdB = new OleDbCommand(consultaSQLB, conn); cmdA.Connection = conn; try { conn.Open(); } catch (Exception excepcion) { MessageBox.Show(excepcion.Message); } if (conn.State == ConnectionState.Open) { try { cmdB.Parameters.AddWithValue("@Legajo", Convert.ToInt32(txtLeg.Text.ToString())); cmdB.Parameters.AddWithValue("@Cargo", Cargo.Text.ToString()); lector = cmdB.ExecuteReader(); while (lector.Read()) { // Si el lector tiene valores significa que el legajo de la BD es == al del textBox y los cargos también son iguales cmdA.Parameters.AddWithValue("@Legajo", Convert.ToInt32(txtLeg.Text.ToString())); cmdA.Parameters.AddWithValue("@Estado", txtEstado.Text.ToString()); cmdA.Parameters.AddWithValue("@Fecha", Convert.ToDateTime(txtFecha.Text.ToString())); cmdA.Parameters.AddWithValue("@Cargo", Cargo.Text.ToString()); cmdA.Parameters.AddWithValue("@Turno", txtTurno.Text.ToString()); cmdA.Parameters.AddWithValue("@Aviso", txtAviso.Text.ToString()); cmdA.ExecuteNonQuery(); } } catch (Exception excepcion) { MessageBox.Show(excepcion.Message); } conn.Close(); this.Close(); } }
string consultaSQLA = "SELECT Legajo FROM InasistenciasSecretario, InasistenciasJefatura, InasistenciasDirector, InasistenciasBedel WHERE Legajo = " + txtLegajo.Text + "";