Entity Framework trying to save empty string as null in database

I'm having to work with a database table, that for whatever reason, requires all entries to have a value(NOT NULL). Not all entries are relevant to the user and they will be leaving entries blank when entering them through a webform. I'm using a FormView databound using Entity Framework.

The problem I'm running into is, that instead of entering an empty or blank string for TextBoxes with no text, it is trying to use a NULL value. Is there a way to just enter a blank string to appease the database constraints?

I wish I could just change these in the database to allow nulls, but unfortunately I don't have access.

Here's a snippet from the aspx:

 <asp:TextBox ID="CustIdTextBox" runat="server" Text='<%# Bind("CustId") %>' />

It looks like entity framework is taking the empty string and deciding to save it to the database as NULL.

Answers


Well we definietly need some code, but I'm guessing the textbox.text property is not initialized, so it's going to give you NULL. Just initialize it to an empty string, or replace the null with string.empty before you update the DB.


Need Your Help

angularjs scope for ngModel is not working as expected

javascript angularjs angularjs-directive angularjs-scope ionic-framework

I have created custom directive drop down in angularjs and ionic-framework. In my dropdown items will open in modal popup which is working very good.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.