database - How to Send DateTime Or DbNull to DB using c#? -
I have a web form (.aspx) that has a text box. My user can enter a value in the text box as a Persian date. What should I do is change texbox.text to datetime, but occasionally, there is no text within it in the text box and so I should take care of it and I should be empty.
How can I include NULL (C #) in DB when I come back blank?
It all depends on how you accessing your data? by hand?
If so; There are two common ways to pass a zero DateTime
; null
was meant to use the original DateTime.MinValue
; To pass on the second date, Nullable & lt; DateTime & gt; After using
(aka DateTime?
), you can find this in your DAL and DBNull.Value
:
You can switch to (if someDate == DateTime.MinValue) {// or "== null" with the tap & lt; Date Time & gt; DateParam.Value = DBNull.Value; } And {dateParm.Value = someDate;
With LINQ-to-SQL, Nullable & lt; DateTime & gt;
The approach should be "just work".
Comments
Post a Comment