[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
Re: Copy child bindingsource to datatable
Try this:
Code:
Dim _tblWeek1 As New DataTable
_tblWeek1 = CType(TblPrimeraSemanaBindingSource.DataSource, DataTable).Copy
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?
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
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