public void Insert(modelo mo) { string connString = "SERVER=localhost;DATABASE=dbteste;UID=root;PASSWORD=;"; MySqlConnection conexao = new MySqlConnection(connString); try { conexao.Open(); MySqlCommand comando = conexao.CreateCommand(); comando.CommandText = "INSERT INTO funcionario(nome, cargo, endereco, telefone, idade)VALUES('" + mo.Nome + "', '" + mo.Cargo + "', '" + mo.Endereco + "', '" + mo.Telefone + "', '" + mo.Idade + "');"; comando.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception("Erro: " + ex.Message); } }
private void btnAdicionar_Click(object sender, EventArgs e) { modelo add = new modelo(); dal da = new dal(); add.Nome = txtAddNome.Text; add.Cargo = txtAddCargo.Text; add.Endereco = txtAddEnd.Text; add.Telefone = txtAddTel.Text; add.Idade = Convert.ToInt16(numAddIdade.Value); da.Insert(add); txtAddNome.Text = ""; txtAddCargo.Text = ""; txtAddEnd.Text = ""; txtAddTel.Text = ""; numAddIdade.Value = 0; frmPrincipal principal = new frmPrincipal(); principal.Update(); }