I have this:
<asp:DropDownList ID="HomeCountry" runat="server"
DataSourceID="CountryListEntityDS"
DataTextField="CountryNameEn"
DataValueField="CountryCode"
AppendDataBoundItems="True"
SelectedValue="<%# Bind('HomeCountry') %>">
<asp:ListItem Text="--Select One--" Value="" />
</asp:DropDownList>
and the datasource is like this:
<asp:EntityDataSource ID="CountryListEntityDS" runat="server"
ConnectionString="name=MainDataModelEntityCont"
DefaultContainerName="MainDataModelEntityCont"
EnableFlattening="False"
EntitySetName="Countries">
</asp:EntityDataSource>
I get the drop down with the countries and the --- Select One --- as the first item correctly. Everything work correctly EXCEPT when I change a record that had a country to the --- select one --- (so not having a country) and press save.
Then it throws:
[SqlException (0x80131904): The UPDATE statement conflicted with the FOREIGN KEY constraint "FK_Account_CountryList".
I have reproduced this error manually in SQL Server Management Studio, it occurs if I try to change a record's Country field from a valid value to a "". The same error is thrown. But when I put Null it works fine. The DB constraint is basically saying you have to have either a valid value or Null.
So it seems to me, the C# code somehow is not resulting in a Null being sent to DB, rather a blank string.
Anyone help greatly appreciated. Many thanks in advance.