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 / March 2005

Tip: Looking for answers? Try searching our database.

error when binding a checkbox and DBNull

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
petro - 02 Mar 2005 00:37 GMT
When I try to bind a checkbox and the data for the field is null I get an
error 'Object cannot be cast from DBNull to Other types'.  Also when I use
AddNew I also get the same error.  I must allow for 0, 1 or null data.

My code is as follows:
ckActive.DataBindings.Add(new Binding("checked", dv, "Active"));
Matt Garven - 04 Mar 2005 07:09 GMT
Hi Petro,

You could try having a default value for that column and not allowing null
in the constraints, or you can investigate the DataBinding.Format and
DataBinding.Parse events and use them to convert the value yourself.

Hope that helps.

Regards,
Matt Garven

> When I try to bind a checkbox and the data for the field is null I get an
> error 'Object cannot be cast from DBNull to Other types'.  Also when I use
> AddNew I also get the same error.  I must allow for 0, 1 or null data.
>
> My code is as follows:
> ckActive.DataBindings.Add(new Binding("checked", dv, "Active"));
petro - 04 Mar 2005 15:49 GMT
Thanks I will try that when I get back around to that project.  

> Hi Petro,
>
[quoted text clipped - 13 lines]
> > My code is as follows:
> > ckActive.DataBindings.Add(new Binding("checked", dv, "Active"));
Kan - 13 Mar 2005 23:38 GMT
I have exactly same problem.
To fix it, call CurrencyManager.Refresh before you call
CurrencyManager.EndCurrentEdit. Because you need to notify the
underlaying dataset that a new has been added first!
simple.

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.