Wednesday, July 23, 2008

Blank form field results in a null insert

Just a quick little note regarding empty strings and null values.

If you are using a sql or object data source you have the option on the paramters to set convertemptystringtonull to true or false. If set to true, then a blank form field will be treated as a null value. Which means that db column has to accept null otherwise the insert will fail.

I was running into an issue where the insert was failing even though I ConvertEmptyStringtoNull set to false. Turns out you also need to set it to false on the fields within the details view as well. Once I set it to false on both the datasource and the details view, i was able to do an insert and the blank form field was treated as an empty string instead of a null.

No comments: