3
I’m making a CRUD with Winforms in the C#, I have an error entering the date in the birth date field. This displays the following message when trying to save the new record:
Missing operator syntax error in query expression '10/02/1986 00:00'
Below is an excerpt from the code
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();
}
}
Down with String SQL
"INSERT INTO Client (descriptionClient, namesake, address, complement, neighborhood, zip code, status, city, phone1, phone2, cellular1, email, CPF, RG, Oemissor, Dtnasc)VALUES ('Fernando', 'fer', 'street 1', '', 'lemon tree', '00125-455', 2, 1960,'(11) 1111-1111', '( ) -', '(11) 91111-1111', '[email protected]', ' . . -', '111.111.111-11', 'SSP-PS', 10/02/1986 00:00:00); "
What am I doing wrong?
maybe it’s the quotes
– Marco Souza