-2
I have a job to insert, update and delete. The insert and delete are working properly. So, I have a problem with the update that that would be:
cmd.CommandText = "Update carros set placa='" + campoplaca.Text + "', marca='" + campomarca.Text + "' where placa='" + campoplaca.Text + "' and marca= '" + campomarca.Text + "'";
In my project I have as values :
id=int pk
placa=nvarchar
marca=nvarchar
modelo=nvarchar
combustivel=nvarchar
potencia=int
ano=int
preco=int
So my question is how to proceed with this command line. Where already exists plate and mark, my wish Where is to change by the board and then the other fields. More will be needed the and in all?
private void btAtualizar_Click(object sender, EventArgs e)
{
SqlCeConnection conn;
try
{
conn = new SqlCeConnection(" Data Source = C:\\Users\\Admin\\Documents\\Visual Studio 2015\\Projects\\WindowsFormsArrayEx03\\BD_Teste.sdf; Password ='' ");
conn.Open();
MessageBox.Show("ATUALIZADO!!!");
SqlCeCommand cmd = conn.CreateCommand();
cmd.CommandText = "Update carros set placa='" + campoplaca.Text + "', marca='" + campomarca.Text + "' where placa='" + campoplaca.Text + "' and marca= '" + campomarca.Text + "'";
cmd.ExecuteNonQuery();
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace);
}
}
Actually, it’s not even put and for update. The card is your primary key?
– Gabriel Falieri
This way of doing it has a fundamental error. There is a huge security flaw. If you start to fix it, it is already a good way to fix the rest. Veja: http://answall.com/q/104614/101. OU http://answall.com/q/136287/101 (Check most voted, the ceita insists on the error).
– Maniero
@Gabrielfalieri puts "and" or "or" yes to update if necessary. No restrictions. Beware of generalized statements.
– user26552
my primary key is id, but soon I will not use it to update and yes the card
– Raphael Takashi