Update a varchar field with null value
c#, mysql
Solution
Here's the answer I found:
cmd.Parameters.Add(new MySqlParameter("@nomeclube", MySqlDbType.VarChar)).Value = !String.IsNullOrEmpty(usr.Nome_Clube) ? (object)usr.Nome_Clube : DBNull.Value;
Problem
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`.