I have a field clube varchar(50)
that is by default NULL, and it it's not notnull
so it accepts null values. What I need to know is, if I have a value already on this field and I want to make an Update
and set it's value with null
, how would I do that?
I tried to set null
the value of a string
but didnt worked.
IF some condition become true, I want to set this field as NULL
by an Update
.
And as obvious, if the condition become false, I will pass a value and NOT null
value. So I need to do it using MySqlcommand Parameter
. Like:
sql = "UPDATE usuarios SET nome = @nome";
cmd.CommandText = sql;
cmd.Parameter.Add(New MySqlParameter("@nome", MySqlDbType.VarChar)).Value = `variable`;
if the condition is true
= variable = null
else variable != null
.
To set the value to null:
cmd.Parameter.Add(New MySqlParameter("@nome", MySqlDbType.VarChar)).Value = DBNull.Value;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With