I am trying to figure out the best way in an asmx web service to indicate null for a date so that I can insert dbnull.value when the user doesn't enter text into a date field. Currently I have a string field in the class that I am serializing that will serve as the date field. When that string is blank I insert dbnull.value, otherwise I insert the string converted to a datetime. IS this the only way or is there a better way? What about for integers and doubles? Thanks.
+1
A:
I guess it depends on what mechanism you are using to do your database inserts e.g. parameterized SQL, stored procedure, etc. If using parameterized SQL, I think your current solution is fine, although if the database table field for date allows nulls, I don't think it is necessary to pass a value for the date column in the INSERT statement if the date field is blank. If using a stored procedure, you could set the date as an optional parameter with a NULL default value.
BTW, are you using the asp.net ajax mechanism for parsing dates in JSON? e.g.
\/Date(1169125740)\/
//1169125740 is the number of milliseconds since UTC (Midnight January 1, 1970)
Russ Cam
2009-01-04 20:50:19
Thanks. I have taken hte optional parameter approach, since I am using a stored procedure. I'm not using the asp.net date format, I'm using a string property to return the date in a format I want. Maybe cheating a little, but it works.
Chris Westbrook
2009-01-05 03:01:57