Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / October 2004

Tip: Looking for answers? Try searching our database.

Problem with zero length string vs Null when Databinding

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Malcolm - 07 Oct 2004 13:43 GMT
I am writing a front end for an existing Access database (which i dont
really want to change if i can help it) in VB.NET.

For simplicity, i am databinding all controls on the screen using an
untyped dataset.

I have a phoneno column in the database which is setup as follows:

Required: No
Allow zero length: No
Data Type: Text

When i bind this column to a textbox, it correctly shows the value
recorded on the database in the box, including when the database
column is set to Null (when it shows nothing in the textbox)
When i put some text in the box, the table is updated correctly,
however, if i delete the contents of the textbox, i get the following
error when the adapter.update call is made:

Field 'tblAddress.ContactPhoneNo' cannot be a zero-length string

What i actually want it to do is write Null to the database column
rather than a 0 length string.
I am using a command builder, so that handles the update of the
column, and sure enough, checking the parameter for the update of the
phone no col, it shows "" {String}.

Is there a way to write Null to this field without having to write the
update statements myself?

Any help much appreciated

Thanks

Malcolm
Sijin Joseph - 12 Oct 2004 04:54 GMT
Yes, you will have to use the Parse event of the Binding to change empty
strings to DBNull
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fSystemWindowsFormsBindingClassParseTopic.asp


Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> I am writing a front end for an existing Access database (which i dont
> really want to change if i can help it) in VB.NET.
[quoted text clipped - 31 lines]
>
> Malcolm
Malcolm - 12 Oct 2004 12:09 GMT
Thanks, i found an article yesterday which contained an example of the
Parse event, it was just what i needed

Malcolm

> Yes, you will have to use the Parse event of the Binding to change empty
> strings to DBNull
[quoted text clipped - 3 lines]
> http://www.indiangeek.net
> http://weblogs.asp.net/sjoseph

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.