Could someone help me with an Insert ? I'm trying to give insert in the DB but I have to convert the dateTimePicker pro to the right format, I do not know if it is exactly like this, I already tried google and tested it in several ways and none worked for me. The first image is the INSERT, which is in a class. The second image is the own button to insert. The third image is the Database (yes I did in phpmyadmin of wamp msm pq is a very small and simple DB). The error that happens when I try to insert is simply in that throw; Of the insert, and I think it's the question of help. Thank you to anyone who can help. i just cant format the "Datav".
public void inserir_produtov()
{
try
{
string inserir1 = "INSERT INTO venda VALUES (null, '" + Datav.ToString("yyyy-MM-dd HH:mm:ss") + "', '" +
Id + "','" +
Quantidadev + "','" +
Valorv.ToString().Replace(',', '.') + "');";
bancodedados1.ExecutarComandos(inserir1);
}
catch
{
throw;
}
}
Here is the Button to insert:
private void btngravar1_Click(object sender, EventArgs e)
{
vendas.Id = int.Parse(txtidproduto.Text);
vendas.Quantidadev = int.Parse(txtquantidade2.Text);
vendas.Valorv = double.Parse(txtvalor.Text);
vendas.Datav = DateTime.Parse(dateTimePicker1.Text);
if (txtidvenda.Text == "")
{
vendas.inserir_produtov();
Limpar();
MessageBox.Show("Dados inseridos com sucesso.");
}