Modifying Values of Multiple Lines

1

I need a query that modifies multiple values at the same time The idea is more or less this

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

The query is kind of strange because it is in the connection between C # and MySql. How can I do this ? Do I need to change all values that have a certain date, help?

    
asked by anonymous 09.06.2015 / 17:07

1 answer

2

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

Example:

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

Treat your date instead of concatenating and using SqlCommand pass as a 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();
    
09.06.2015 / 17:11