473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

problems with parsing & format in ConvertEventArgs when field value is DBNULL

Neo
I have a table Contacts with a field "Male" which is of type Bit (SQL Server).

I've got two radio buttons in a panel, & one of them is bound to the above field, (so that one can see if the contact is a Male of FeMale - determine or change the gender).
Below is the coding.

BUT, if i have a record where the Male field is "NULL", then all hell breaks lose, & i get the below error

An unhandled exception of type 'System.InvalidCastException' occurred in system.windows.forms.dll
Additional information: Object cannot be cast from DBNull to other types.

Any solutions??? (i'm totally lost)

Code ->

Dim dbnGender As New Binding("Checked", poDataTable, "Male")
AddHandler dbnGender.Format, AddressOf MaleToBollean
AddHandler dbnGender.Parse, AddressOf BooleanToMale
rdoMale.DataBindings.Add(dbnGender)

Protected Sub MaleToBollean(ByVal sender As Object, ByVal e As ConvertEventArgs)
Try
e.Value = e.Value
Catch exp As Exception
MessageBox.Show("Data entry error: " & exp.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub

Protected Sub BooleanToMale(ByVal sender As Object, ByVal e As ConvertEventArgs)
Try
e.Value = IIf(e.Value, 1, 0)
Catch exp As Exception
MessageBox.Show("Data entry error: " & exp.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Nov 21 '05 #1
1 1830
Try something like:

If IsDBNull(e.value) then
Terp
"Neo" <ne*@learning.net> wrote in message news:uj*************@TK2MSFTNGP12.phx.gbl...I have a table Contacts with a field "Male" which is of type Bit (SQL Server).
I've got two radio buttons in a panel, & one of them is bound to the above field,
BUT, if i have a record where the Male field is "NULL", then all hell breaks lose, & i get the below error
An unhandled exception of type 'System.InvalidCastException' occurred in system.windows.forms.dllAdditional information: Object cannot be cast from DBNull to other types.

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dr. Paul Caesar - CoullByte (UK) Limited | last post by:
Hi all! I have a windows form that is bound to a dataset. Using VS 2005 & .NET Framework Beta 2. In my dataset I have a colum called Warranty that is a smallint on SQL Server 2000(SP4). ...
3
by: Slonocode | last post by:
I have some textboxes bound to an access db. I wanted to format the textboxes that displayed currency and date info so I did the following: Dim WithEvents oBidAmt As Binding oBidAmt = New...
1
by: Rich | last post by:
Hello, I have some datefields in a dataset (ds1). I bind some textbox controls on a windows form to these date fields in ds1, but I only want to see 01/01/2004 instead of 1/1/2004 8:00:00 AM. ...
1
by: Agnes | last post by:
In my tables, there are invoicedate, as i use databinding, bind the invoicedate to the textbox, It show mm-dd-yyyy time. I need to change it into date dd-mm-yyyy only without time . how can i do...
13
by: Agnes | last post by:
I know someone post the solution before, but I didn't keep in mind . So I am sorry to ask the same question again I had bind a datatime to the textbox name txtInvoice I want it displayed in...
1
by: Neo | last post by:
I have a table Contacts with a field "Male" which is of type Bit (SQL Server). I've got two radio buttons in a panel, & one of them is bound to the above field, (so that one can see if the contact...
2
by: Neo | last post by:
I have a table Contacts with a field "Male" which is of type Bit (SQL Server). I've got two radio buttons in a panel, & one of them is bound to the above field, (so that one can see if the...
5
by: Carrie | last post by:
Good Morning, I have a combobox whose list is bound to DataSet1.Sales Growth Options.Sales Growth. The data is double and I would like it displayed as a percentage. I have tried two things: ...
2
by: Cerebral Believer | last post by:
Hi folks, Can anyone help me with this form: http://futurebydesign-music.com/_member/club_fbd_reg.php I have followed to coding instructions aas closely as I can, but I am getting errors...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.