private void btnPesquisar_Click(object sender, EventArgs e) { try { DB_CONEXAO.ConnectionKey(); pesquisaNome = "Select id, nome, end, email, telefone from cliente where nome = @nome"; DB_CONEXAO.comando = new MySqlCommand(pesquisaNome, DB_CONEXAO.ConnectionKey()); DB_CONEXAO.comando.Parameters.AddWithValue("@nome", txtNome.Text); DB_CONEXAO.OpenConnection(); DB_CONEXAO.dr = DB_CONEXAO.comando.ExecuteReader(); while (DB_CONEXAO.dr.Read()) { txtId.Text = Convert.ToString(DB_CONEXAO.dr["id"]); txtEnd.Text = Convert.ToString(DB_CONEXAO.dr["end"]); txtEmail.Text = Convert.ToString(DB_CONEXAO.dr["email"]); txtTelefone.Text = Convert.ToString(DB_CONEXAO.dr["telefone"]); } } catch (Exception ex) { MessageBox.Show("Erro na pesquisa: " + ex.Message, "Ops", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } finally { DB_CONEXAO.CloseConnection(); } }
private void CarregarGrid() { string select = "Select id, nome, end, email, telefone from cliente"; DB_CONEXAO.da = new MySqlDataAdapter(select, DB_CONEXAO.ConnectionKey()); DataTable dt = new DataTable(); DB_CONEXAO.da.Fill(dt); dgvClientes.DataSource = dt; DB_CONEXAO.CloseConnection(); }
private void ckbNovo_CheckedChanged(object sender, EventArgs e) { //Desabilitando/habilitando button Cadastrar if (ckbNovo.Checked) { btnCadastrar.Enabled = true; txtEmail.Clear(); try { DB_CONEXAO.ConnectionKey(); //Capturando o próximo id que será adicionado string nextId = " select max(id)+1 as 'next id' from cliente;"; DB_CONEXAO.comando = new MySqlCommand(nextId, DB_CONEXAO.ConnectionKey()); DB_CONEXAO.OpenConnection(); DB_CONEXAO.dr = DB_CONEXAO.comando.ExecuteReader(); while (DB_CONEXAO.dr.Read()) { // Obtendo através o textbox id txtId.Text = Convert.ToString(DB_CONEXAO.dr["next id"]); } } catch (Exception ex) { // MessageBox.Show(ex.Message); MessageBox.Show("Erro ao incluir" + ex.Message + MessageBoxIcon.Error); } finally { //Fechando conexões DB_CONEXAO.CloseConnection(); } } else { btnCadastrar.Enabled = false; txtId.Clear(); } }