Modifying Values of Multiple Lines

Asked

Viewed 361 times

1

I need a query that modifies several values at the same time That’s kind of the idea

"INSERT INTO registros(Envio) VALUES('1') where Aviso = '" + DdataAtual.Year + "-" + DdataAtual.Month + "-" + DdataAtual.Day + "' "

The query is a little strange because it is in the connection between C# and Mysql. How can I do that ? I need to modify all values that have a certain date, helps ?

  • Yuri, I updated my answer with a solution to pass the parameter more securely and more organized, if you want to test.

1 answer

2

If you want to modify or change values of a table you use the UPDATE and not the INSERT.

Example:

UPDATE registros
SET Envio = '1'
WHERE Aviso = @dataFormatada 

Treat your date instead of concatenating and using SqlCommand pass as parameter. This way:

string sql = "UPDATE registros SET Envio = '1' WHERE Aviso = @dataFormatada;";

SqlCommand cmd = new SqlCommand(sql, conn); /* conn = sua conexão */

cmd.Parameters.AddWithValue("@dataFormatada", DdataAtual.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery();
  • Nooossa I was very juvenile now, thank you !!!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.