I just read out very nice answers to save null into database column using
string.IsNullOrWhiteSpace(textbox.tex) ? (object)textbox.text: DBNull.Value;
or using
cmd.Parameters.AddWithValue("foo",
foo == null ? (object)DBNull.Value : (object)foo);
and I tried with others too but it's not working for me as I am not very expert of C# language but I must want to save null into my SQL Server database column.
Here is my code which I tried to save null value but it sends empty string which is not my requirement.
oCourseRegistrationPaypal.UserTheoryTrainingDate4 = Convert.ToString(DBNull.Value);
So when I write
oCourseRegistrationPaypal.UserTheoryTrainingDate4 = null;
it gives me error that my procedure wants parameter which was not supplied but I know that I have supplied null to it.
When I write
oCourseRegistrationPaypal.UserTheoryTrainingDate4=Convert.ToString(DBNull.Value);
it saves the empty string in my database column but I need a null
value there.
When I manually save null values in stored procedure it accepts null and save null but why it is not accepting
oCourseRegistrationPaypal.UserTheoryTrainingDate4 = null;
from my C# code?
Is there a better way to do this?