473,511 Members | 9,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1837
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
1078
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
3071
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
9390
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
6409
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
9365
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
306
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
2806
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
3612
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
1929
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
7148
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7430
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...
1
7089
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
7517
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
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
451
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.