0
I have some data registered in the database, and I wanted to know how to change the function of inserting in the database to change the data, using a Button
, I can pull the dice and throw them at us TextBoxs
through the DataGrid
, but wanted to change and save the amendments
Here I use my button btnSalvar
to insert into the bank
private void btnSalvar_Click(object sender, EventArgs e)
{
// campos vazios
if (txtNome.Text.Equals(""))
{
System.Windows.Forms.MessageBox.Show("O nome do produto está vazio, por favor digite algo");
}
else if (txtPreco.Text.Equals(""))
{
if (txtPreco.Text.Equals(""))
{
System.Windows.Forms.MessageBox.Show("O Preço do produto está vazio, por favor digite algo");
}
else
{
}
//fim dps campos vazios
}
//eniando para o banco
else
{
try
{
conectar.Open();
//Convertendo
Converter = Convert.ToDecimal(txtPreco.Text);
//MessageBox.Show("Conectado");
MySqlCommand Inserir = new MySqlCommand();
Inserir.Connection = conectar;
Inserir.CommandText = "INSERT INTO Produto (Nome, Descricao, Preco, `status`) VALUES (@peca, @nome, @quantidade, @dataentrada)";
Inserir.Parameters.AddWithValue("@peca", txtNome.Text);
Inserir.Parameters.AddWithValue("@nome", txtDescricao.Text);
Inserir.Parameters.AddWithValue("@quantidade", txtPreco.Text);
Inserir.Parameters.AddWithValue("@dataentrada", ckbAtiv.Checked);
Inserir.ExecuteNonQuery();
conectar.Close();
MessageBox.Show("Cadastro Realizado!", "Concluido",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
selecionarCategoria();
}
catch (SqlException)
{
MessageBox.Show("Falha na conexao!", "falha",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
}
And here I can play the values of DataGrid
for the TextBoxs
private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
txtNome.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
txtDescricao.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
txtPreco.Text = dataGridView1.CurrentRow.Cells[3].Value.ToString();
}
@Cypherpotato edited the question to try to make it clearer
– Pietro Nunciaroni