private List <ProfissaoPaciente> getProfissao() { try { conn.Open(); com.Connection = conn; SqlCommand cmd = new SqlCommand("select * from Profissao order by nomeProfissao", conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { profissao = new ProfissaoPaciente { nome = (string)reader["nomeProfissao"], IdProfissao = (int)reader["IdProfissao"], }; listaProfissoes.Add(profissao); } conn.Close(); } catch (Exception) { if (conn.State == ConnectionState.Open) { conn.Close(); } MessageBox.Show("Por erro interno é impossível visualizar os dados!", "Atenção!", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(listaProfissoes); }
private void dataGridViewProfissao_MouseDoubleClick(object sender, MouseEventArgs e) { int i = dataGridViewProfissao.CurrentCell.RowIndex; profissao = null; foreach (var p in auxiliar) { if (p.nome == dataGridViewProfissao.Rows[i].Cells[0].Value.ToString()) { profissao = p; } } if (profissao != null) { txtNome.Text = profissao.nome; } }