ConvertEmptyStringToNull not working with ASP.NET SqlDataSource Parameters

The ConverEmptyStringToNull property of SqlDataSource Parameters does not work for asp.net 2.0 applications. You probably need this kind of setting when you have a stored procedure that can handle null as a valid parameter value, but the framework assumes nothing has been supplied and prevents the select/insert/update/delete statement from executing.

You can however, get it to work if you set the CancelSelectOnNullParameter property of the SqlDataSource to false. This is a known issue, according to microsoft from this post:

The common scenario is a TextBox bound to a ControlParameter, whose initial value is empty string (gets converted to null because ConvertEmptyStringToNull is true by default), where you only want the query to execute when the user has actually supplied a non-empty value. I agree however, that there are some scenarios where you want to execute the SelectCommand anyway even is there is a null parameter (which gets converted to DbNull by SqlDataSource), and that is precisely why we allow you to set the CancelSelectOnNullParameter property to false.

Not sure if this has been addressed in later versions of the .NET framework.

Print Friendly

2 Comments

  1. Dar says:

    Thanks champ.

  2. youl says:

    and forget the OldValuesParameterFormatString parameter of the datasource

Leave a comment