Results 1 to 4 of 4

Thread: Data Form Wizard Woes

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Posts
    30

    Thumbs down Data Form Wizard Woes

    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
    [email protected]

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    can you post the code the wizard generated for this event please ?

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Posts
    30

    Code

    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

  4. #4
    Lively Member Kenbuddy's Avatar
    Join Date
    Jul 2002
    Location
    Cypress, TX
    Posts
    96
    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

    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).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width