Change column data [closed]

0

How can I change the column data? I wanted to change some bits to false but I do not know how.

        using (SqlCommand cmdadd = new SqlCommand("INSERT into Usuarios (Cadastro) VALUES (@Cadastro)", connection2))
    {
cmdadd.Parameters.Add(new SqlParameter("@Cadastro", false));
    }

But I did not want to add, wanted to change, what would the code look like?

    
asked by anonymous 19.11.2017 / 13:39

2 answers

0

Instead of insert use the Update command, it would look something like this:

"UPDATE [Nome da Tabela SET [Nome do campo] = [Expressão] WHERE Cadastro = false"

So sql will override field values with SET values and only in the field where Cadastro is False, if you do not use a Where you can end up editing all of the table, which would certainly be inconvenient for you, if the explanation was not clear, visit the source.

Source: link

    
19.11.2017 / 16:36
0
using (SqlCommand cmdadd = new SqlCommand("UPDATE Usuario set Cadastro = @Cadastro where xxx = @yyy", connection2))
{
    cmdadd.Parameters.Add(new SqlParameter("@Cadastro", false));
    cmdadd.Parameters.Add(new SqlParameter("@yyy", false));
}

The xxx column would be a column of a unique identifier for your table.

do not forget to send the parameter to do update .. pq update without where is complicated: P

    
19.11.2017 / 16:30