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?
 
käµfm³d 👽Connect With a Mentor Commented:
Ah, forgot about the XML  : \

Let's try encoding the brackets:

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

Open in new window

0
 
käµfm³d 👽Commented:
Try this:

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

Open in new window

0
 
Vikram Singh SainiConnect With a Mentor Software 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.
0
 
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.