I'm doing a CRUD with Winforms in C # , I'm having an error inserting the date in the date field. The following message appears when attempting to write the new record:
Operator syntax error missing in query expression '10 / 02/1986 00:00 '
Follow the code snippet below
string sql = "INSERT INTO Cliente (descCliente, nomefantasia, endereco, complemento, bairro, cep, estado, cidade, "
+ "telefone1, telefone2, celular1, email, CPF, RG, OEmissor, DtNasc)"
//, CPF, RG, OEmissor, bloqueado, mensalista) "
+ "VALUES ('" + txtnome.Text + "', "
+ "'" + txtFantasia.Text + "', "
+ "'" + txtRua.Text + "', "
+ "'" + txtComplemento.Text + "', "
+ "'" + txtBairro.Text + "', "
+ "'" + mskCEP.Text + "', "
+ Convert.ToInt32(txtEstado.Text) + ", "
+ Convert.ToInt32(txtCidade.Text) + ","
+ "'" + mskFone1.Text + "', "
+ "'" + mskfone2.Text + "', "
+ "'" + mskcelular.Text + "', "
+ "'" + txtemail.Text + "', "
+ "'" + mskCPF.Text + "', "
+ "'" + mskRG.Text + "', "
+ "'" + txtEmissor.Text + "', "
+ Convert.ToDateTime(mskDOB.Text) + "); ";
//+ false + ", "
//+ false + ");";
OleDbConnection conn = new OleDbConnection(connStr);
OleDbCommand cmd = new OleDbCommand(sql , conn);
cmd.CommandType = CommandType.Text;
conn.Open();
try
{
int i = cmd.ExecuteNonQuery();
if (i>0)
{
MessageBox.Show("inclusão efetuada com sucesso");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
}
Below the String SQL
"INSERT INTO Client (descClient, name, address, add, neighborhood, zip, city, phone1, phone2, cellular1, email, CPF, RG, OEmissor, DtNasc) VALUES ('fernando', ' 'lane 1', '' lime tree '', '00125-455', 2, 1960, '(11) 1111-1111', '(11) 91111-1111', 'me @ me .com ','. ',' 111.111.111-11 ',' SSP-PS ', 10/02/1986 00:00:00); "
What am I doing wrong?