Working with empty non-string data in json and asp.net ajax
I am trying to find a better way in the asmx web service to specify null for a date so that I can insert a dbnull.value when the user does not enter text in the date field. I currently have a string field in a class that I am serializing that will serve as a date field. When this line is empty, I insert dbnull.value, otherwise I insert a string converted to datetime. Is this the only way or is there a better way? What about integers and pairs? Thank.
source to share
I guess it depends on what mechanism you are using to do your database inserts, eg. parameterized SQL, stored procedure, etc. If using parameterized SQL, I think your current solution is fine, although if the database table field for the date is nullable, I don't think it is necessary to pass the value for the date column to the INSERT if the date field is empty. If you are using a stored procedure, you can set the date as an optional parameter with a default null value.
By the way, are you using the asp.net ajax mechanism to parse dates to JSON? eg.
\/Date(1169125740)\/
//1169125740 is the number of milliseconds since UTC (Midnight January 1, 1970)
source to share