C
C#2y ago
yumo

✅ crud error checkbox not working

Im doing a CRUD app and my button isnt working properly This is the code i have to the insert button
private void btnInserir_Click(object sender, EventArgs e)
{
SqlCeConnection con = new
SqlCeConnection(@"Data Source=|DataDirectory|\myDB.sdf");
con.Open();
string query = "INSERT INTO tempos_maquina(" + "id,codigo,data_inicio,data_fim,rh,inicio,fim,tempo_peca,terminada,fr)" + "VALUES (@id,@codigo,@data_inicio,@data_fim,@rh,@inicio,@fim,@tempo_peca,@terminada,@fr)";
SqlCeCommand cmd = new SqlCeCommand(query, con);
cmd.Parameters.AddWithValue("@id", txtID.Text);
cmd.Parameters.AddWithValue("@codigo", txtCodigo.Text);
cmd.Parameters.AddWithValue("@data_inicio", txtDataInicio.Text);
cmd.Parameters.AddWithValue("@data_fim", txtDataFim.Text);
cmd.Parameters.AddWithValue("@rh", cmbRH.Text);
cmd.Parameters.AddWithValue("@inicio", txtInicio.Text);
cmd.Parameters.AddWithValue("@fim", txtFim.Text);
cmd.Parameters.AddWithValue("@tempo_peca", txtTempoPeca.Text);
cmd.Parameters.AddWithValue("@terminada", chkTerminada.Text);
cmd.Parameters.AddWithValue("@fr", txtFr.Text);

if (chkTerminada.Checked)
{
txtDataFim.Text = DateTime.Now.ToString("dd / MM / yyyy");
}
else
{
txtFr.Text = "FR";
}

cmd.ExecuteScalar();
MessageBox.Show("Registo Inserido");
con.Close();
this.Close();
}
private void btnInserir_Click(object sender, EventArgs e)
{
SqlCeConnection con = new
SqlCeConnection(@"Data Source=|DataDirectory|\myDB.sdf");
con.Open();
string query = "INSERT INTO tempos_maquina(" + "id,codigo,data_inicio,data_fim,rh,inicio,fim,tempo_peca,terminada,fr)" + "VALUES (@id,@codigo,@data_inicio,@data_fim,@rh,@inicio,@fim,@tempo_peca,@terminada,@fr)";
SqlCeCommand cmd = new SqlCeCommand(query, con);
cmd.Parameters.AddWithValue("@id", txtID.Text);
cmd.Parameters.AddWithValue("@codigo", txtCodigo.Text);
cmd.Parameters.AddWithValue("@data_inicio", txtDataInicio.Text);
cmd.Parameters.AddWithValue("@data_fim", txtDataFim.Text);
cmd.Parameters.AddWithValue("@rh", cmbRH.Text);
cmd.Parameters.AddWithValue("@inicio", txtInicio.Text);
cmd.Parameters.AddWithValue("@fim", txtFim.Text);
cmd.Parameters.AddWithValue("@tempo_peca", txtTempoPeca.Text);
cmd.Parameters.AddWithValue("@terminada", chkTerminada.Text);
cmd.Parameters.AddWithValue("@fr", txtFr.Text);

if (chkTerminada.Checked)
{
txtDataFim.Text = DateTime.Now.ToString("dd / MM / yyyy");
}
else
{
txtFr.Text = "FR";
}

cmd.ExecuteScalar();
MessageBox.Show("Registo Inserido");
con.Close();
this.Close();
}
It's not giving me any error but if the check box is enabled it should be placing the current data into the field called "Data Fim" and if isnt checked it would place "FR" in the column FR (as shown in the screenshot) Can someone help me why this is happening?
3 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
yumo
yumo2y ago
thank you @Thaumanovic it's working correctly now!
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts