I created a form to change a table, but my update is not working.
cnxCli.sel =/*"set dateformat dmy \n"+ */
"update Cliente" +
"set Nome = '" + txtNome.Text +"'," +
"Rg = '" + mskRg.Text + "'," +
"Cpf ='" + mskCpf.Text + "'," +
"Celular ='" + mskCelular + "'," +
"Telefone ='" + mskTelefone + "'," +
"DataNascimento = '" + mskNascimento.Text + "'," +
"Endereco ='" + txtEndereco.Text + "'," +
"Bairro='" + txtBairro.Text + "'," +
"Cidade='" + "'," +
"Cep ='" + mskCep.Text + "'," +
"Observacao='" + txtObs.Text + "'" +
"where IDCliente =" + IdCliSel;
cnxCli.selCmd.CommandText = cnxCli.sel;
bool deuErro = false;
try
{
cnxCli.selCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
deuErro = true;
//throw;
}
if (!deuErro)
MessageBox.Show("Cadastro do cliente " + IdCliSel + " atualizado com sucesso!");
The exception thrown: System.Data.SqlClient.SqlException - Incorrect syntax near 'Nome'
.
For me the syntax seems correct, so much so that I copied the code straight from SQL Server 2014, where I had just run the command.