private void btnBuscarMilitar_Click(object sender, EventArgs e) { frmBuscarMilitar ofrmBuscarMilitar = new frmBuscarMilitar(); ofrmBuscarMilitar.ShowDialog(); }
private void btnBuscarMilitar_Click(object sender, EventArgs e) { frmBuscarMilitar ofrmBuscarMilitar = new frmBuscarMilitar(); ofrmBuscarMilitar.ShowDialog(); string cCodigo = ofrmBuscarMilitar.cCodigo; // Si selecciono un registro if (cCodigo != "" && cCodigo != null) { // Mostrar el codigo txtCedula.Text = Convert.ToString(cCodigo).Trim(); try { // Step 1 - clsConexion MySqlConnection MyclsConexion = new MySqlConnection(clsConexion.ConectionString); // Step 2 - creating the command object MySqlCommand MyCommand = MyclsConexion.CreateCommand(); // Step 3 - creating the commandtext //MyCommand.CommandText = "SELECT * FROM paciente WHERE cedula = ' " + txtCedula.Text.Trim() + "' " ; MyCommand.CommandText = "SELECT * from militares WHERE cedula = '" + txtCedula.Text.Trim() + "'"; // Step 4 - connection open MyclsConexion.Open(); // Step 5 - Creating the DataReader MySqlDataReader MyReader = MyCommand.ExecuteReader(); // Step 6 - Verifying if Reader has rows if (MyReader.HasRows) { while (MyReader.Read()) { txtRango.Text = MyReader["rango"].ToString(); txtNombre.Text = MyReader["nombre"].ToString(); txtApellido.Text = MyReader["apellido"].ToString(); } //this.cModo = "Buscar"; //this.Botones(); } else { MessageBox.Show("No se encontraron registros con esta cedula...", "SisGesOfiEjecutivo", MessageBoxButtons.OK, MessageBoxIcon.Information); //this.txtCedula.Focus(); //this.cModo = "Inicio"; //this.Botones(); //this.Limpiar(); //this.txtID.Focus(); } // Step 6 - Closing all MyReader.Close(); MyCommand.Dispose(); MyclsConexion.Close(); } catch (Exception MyEx) { MessageBox.Show(MyEx.Message); } } }