7
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 directly from SQL Server 2014, where I had just run the command.
I agree with everything you said. The code has been causing several problems. But this is still my first system. Besides, I’m using the spare minutes at work or after dinner to program. Until 2 months ago I could spend a lot of time programming, now no more. Thanks for the feedbacks.
– Ezequiel Barbosa