Click here to Skip to main content
15,895,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I have a web method as shown below with nullable DateTime type as parameter.
While consuming the web service, it is expecting DateTime value and not accepting null.

[WebMethod()]
public void UpdateRecord(DateTime? updatedDT, ....)
{
}

When calling the function as shown below

UpdateRecord(null, ....);
not able to pass null to DateTime parameter.

Please suggest an appropriate procedure to achieve the same.
Posted
Updated 18-Nov-13 23:21pm
v2

1 solution

Assuming you can't modify the UpdateRecord method to support nullable types, then you could:
1) Use the Null Coalescing operator to convert it to a DateTime:
C#
UpdateRecord(myNullableDateTime ?? DateTime.MinValue);

2) Create a version of UpdateRecord which does accept nullable types and calls the original version via the null Coalescing operator as above.

Or I may have misread that: but C# will allow this perfectly happily:

C#
...
UpdateRecord(null);
    }
void UpdateRecord(DateTime? dt)
    {
    ...
    }
So I don;t think so...
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900