PDA

Click to See Complete Forum and Search --> : Data Form Wizard Woes


rplumbo
Jan 10th, 2002, 04:20 PM
Hello - I'm currently trying to develop a small app to help me keep track of my eBay sales. I entered all data into excel, exported it to access and let the VB.NET data form wizard do the rest. It was working fine until I attempted to add a combo box. Now it throws:

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

This exception is thrown after the "Add" button is pressed, which used to just add a new row to the database upon which I could add my data. Does this ring any bells with anyone?? Any help would be MUCH appreciated!!

Thank you!
Sincerely,
Reid V. Plumbo
rplumbo@hotmail.com

alex_read
Jan 11th, 2002, 04:08 AM
can you post the code the wizard generated for this event please ?

rplumbo
Jan 11th, 2002, 08:46 AM
Thank you! Tell me if you need more code than this, or if you'd just like the entire project mailed to you. THANK YOU!

Private Sub mfp_btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mfp_btnAdd.Click
Try
'Clear out the current edits
Me.BindingContext (objmyTransactions, "Transactions").EndCurrentEdit()

'It breaks on this next line.
Me.BindingContext(objmyTransactions, "Transactions").AddNew()
Catch eEndEdit As System.Exception
System.Windows.Forms.MessageBox.Show(eEndEdit.Message)
End Try
Me.objmyTransactions_PositionChanged()

End Sub

Kenbuddy
Mar 20th, 2004, 05:03 PM
The problem is caused from binding certain types of controls that can't display DBNull values properly, to the dataset. Two examples are the DateTimePicker, and the Checkbox. Here is an MSDN article that describes the problem:

http://support.microsoft.com/default.aspx?scid=kb;en-us;313513 (http://)

I was having the same error and found that in my case, it was a Checkbox. I didn't use the solution provided in the MSDN article. I just made sure that the field in the dataset that the checkbox was bound to was not null before doing the "resumebinding" command on the binding context object (or in your case, AddNew).