Blogs
 
Wednesday, December 14, 2005

On a current project that was using the 2.0 ObjectDataSource, we encountered a bug that would not allow a field in the database to be updated with a blank string when it already had a value in it. Being new to the ASP.NET 2.0 ObjectDataSource, I proceeded to dive right in and correct the bug.

The problem was that each time the item was updated with a blank string, the ObjectDatasource was posting the value as “Nothing”. However, if new data was entered in over the old data, the value was posted with the newly entered data.

After some toying around with the problem through debugging, I found that in order to post a blank string from an ObjectDataSource you needed two key attributes in your parameter tag: DefaultValue and ConvertEmptyStringToNull.

<asp:Parameter Name="Description" Type="String" 
DefaultValue="" ConvertEmptyStringToNull="false" />

By setting the default value to an empty string and telling the ObjectDataSource not to convert that empty string to a null value, the value was now coming back as an actual blank string.

I will give myself a little pat on the back for figuring this one out (great confidence booster that pat on the back is! Heck, I feel happy just thinking about how good I will feel when I do give myself that pat).

Jason McEvoy



Archive

Recent Entries

Blogs we read


Page 1 Of 1 (1 items)