Results 1 to 5 of 5

Thread: [RESOLVED] Copy child bindingsource to datatable

  1. #1
    Hyperactive Member
    Join Date
    Aug 05
    Posts
    256

    Resolved [RESOLVED] Copy child bindingsource to datatable

    hi, i'm trying to copy a bindingsource (child table) to a datatable. This is what i did:
    Code:
                Dim _tblWeek1 As New DataTable
                _tblWeek1 = CType(TblPrimeraSemanaBindingSource.DataSource.TblPrimeraSemana, DataTable).Copy
    For some reason this code works but only for parent tables not for child table.
    This is the error i'm getting: Public member 'TblPrimeraSemana' on type 'BindingSource' not found.

    Can some help me on this one?

    Regards,
    2005

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 06
    Location
    Providence, RI - USA
    Posts
    9,167

    Re: Copy child bindingsource to datatable

    Try this:
    Code:
     Dim _tblWeek1 As New DataTable
     _tblWeek1 = CType(TblPrimeraSemanaBindingSource.DataSource, DataTable).Copy
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3
    Hyperactive Member
    Join Date
    Aug 05
    Posts
    256

    Re: Copy child bindingsource to datatable

    hi, stanav. thanks

    When i do it like that, removing the name of the table after the ".datasource.", i receive the following error:

    Unable to cast object of type 'System.Windows.Forms.BindingSource' to type 'System.Data.Datatable'.

    And by the way, on the form load i did loaded the data:
    Code:
    Me.TblPrimeraSemanaTableAdapter.Fill(Me.PPR432RevCDataSet.tblPrimeraSemana)

    Any other idea?

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 06
    Location
    Providence, RI - USA
    Posts
    9,167

    Re: Copy child bindingsource to datatable

    Since it's a typed dataset, you have to cast it to its type. However, I'm not sure if you can cast the typed datatable to a generic datatable. That's why I hate those typed dataset/datatable. They are so restricted...
    Try this:
    Code:
    Dim tbl as PPR432RevCDataSet.tblPrimeraSemana = DirectCast(TblPrimeraSemanaBindingSource.DataSource, PPR432RevCDataSet.tblPrimeraSemana).Copy()
    'Now, I'm not sure if you can cast tbl to a datatable or not. But you should be able to use tbl as is though
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  5. #5
    Hyperactive Member
    Join Date
    Aug 05
    Posts
    256

    Re: Copy child bindingsource to datatable

    Thanks stanav, the previous code didn't worked. But i make it work by doing this:
    Code:
    _tblWeek1 = PPR432RevCDataSet.Tables("tblPrimeraSemana")
    Thanks for the help anyway. Appreciated!

    2005

Posting Permissions

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