Nullable System.DateTime in Web.Config (System.DateTime?)

I use the Stored Procedure Profile Provider in my ASP.NET web Project.

One of the values I need to store on the User Object is called PaymentDate. The datatype need to be DateTime, but since the value can be NULL I need the datatype it to be nullable.

In web.config I do like this:

<add name="PaymentDate" defaultValue="[null]" type="System.DateTime?" customProviderData="PaymentDate;DateTime;8" />

Open in new window


The code compile, and everything seems to work fine. But, when I open the web page I get a web.config error saying "Cannot load type System.DateTime?".

If I change "System.DateTime?" to "System.DateTime" it is not possible to set p.PaymentDate = null; (PaymentDate cannot be null).

So, how can I set the PaymentDate Type to be Nullable DateTime in web.config?
LVL 1
webressursAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kaufmed   ( ⚆ _ ⚆ )Patches? We Ain't Got No Patches! We Don't Need No Patches! I Don't Have to Push You No Stinkin' Patches!Commented:
Try this:

type="System.Nullable<System.DateTime>"

Open in new window

Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:
Hi,

If kaufmed® solution works, then it's great.

Or you can use solution idea from link default value as null for a bool type in a profile provider for creating custom type.
webressursAuthor Commented:
kaufm:

When writing type="System.Nullable<System.DateTime>" I get the error : Tag was not closed. When running the website I get the error: Configuration file is not well-formed XML.
kaufmed   ( ⚆ _ ⚆ )Patches? We Ain't Got No Patches! We Don't Need No Patches! I Don't Have to Push You No Stinkin' Patches!Commented:
Ah, forgot about the XML  : \

Let's try encoding the brackets:

type="System.Nullable&lt;System.DateTime&gt;"

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.