I have an insertparameter that is a non null nvarchar(MAX) and I set it using:
sds_accountDetail.InsertParameters["firstName"].DefaultValue = "";
But it still say "Cannot insert the value NULL into column 'firstName'", what am I doing wrong?
I was just looking for a solution to this problem, and I encountered this page as the first Google result. I know the question is from 2012, but I decided to post for the sake of other people having the same problem. The "right" way of solving this is setting the ConvertEmptyStringToNull property of the problematic Parameter to false. It can be done in the .aspx file, like this:
<InsertParameters>
<!-- (...) -->
<asp:Parameter Name="firstName" ConvertEmptyStringToNull="false" />
<!-- (...) -->
</InsertParameters>
or in the code-behind, like this:
sds_accountDetail.InsertParameters["firstName"].ConvertEmptyStringToNull = false;
"Solved" it by appending a space in the string:
sds_accountDetail.InsertParameters["firstName"].DefaultValue = " ";
String.Emptyto see if that works? Like this:sds_accountDetail.InsertParameters["firstName"].DefaultValue = String.Empty;