Question

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.

Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top