Print Page | Close Window

Insert NULL Into Database Field

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2010
Printed Date: 15-Apr-2025 at 1:08pm


Topic: Insert NULL Into Database Field
Posted By: cjohnson84
Subject: Insert NULL Into Database Field
Date Posted: 27-Jul-2010 at 11:20am

I have bound the contents of the "Employees" table in my database to a datagrid in my DevForce 2010 Silverlight application.

The "MiddleName" field in the "Employees" table is defined as a Nullable Varchar(30) in the database.
 
If I edit records in the datagrid and then save back to the database how do I ensure that NULL values are written back to the database instead of empty strings for the "MiddleName" field if the "MiddleName" field was left blank in the datagrid? 



Replies:
Posted By: davidklitzke
Date Posted: 28-Jul-2010 at 4:19pm

A BeforeSet property interceptor action would do the trick.  I guess you could generalize it further to any entity, and in the logic in the interceptor determine if the set should be cancelled.

 



Posted By: cjohnson84
Date Posted: 30-Jul-2010 at 12:22pm
Thank you for the suggestion!  I was able to add a "BeforeSet" method to my injected Baseentity class to solve the problem.



Print Page | Close Window