Change column data

Asked

Viewed 85 times

0

How can I change column data? I wanted to change some bits to false but I don’t know how.

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

But I didn’t want to add, I wanted to change, how the code would look?

  • 1

    https://www.devmedia.com.br/comandos-basicos-em-sql-insert-update-delete-e-select/37170

2 answers

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 column xxx would be a column of a unique identifier of your table.

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

0


Instead of using 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 overwrite the field values with the SET values and only in the field where the Register is False, if you don’t 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: https://sqlcomoumtodo.wordpress.com/category/update/

Browser other questions tagged

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