Reputation: 6605
there are soo many examples in c#, but the application is VB. and it seems the equivalent does not want to work for me.
Dim dt As New DataTable()
Dim bsMain As New BindingSource()
bsMain.DataSource = dgvMainLookUp.DataSource
dt = CType(bsMain.DataSource, DataTable)
the error is on the last line, and is as follow:
Unable to cast object of type System.Windows.Forms.BindingSource to type System.Data.DataTable.
please help me figure out what i am doing wrong. converting DataSource to DataTable should not be so painful
Upvotes: 0
Views: 4332
Reputation: 1573
I am guessing that you are setting dgvMainLookUp.DataSource to bsMain or another BindingSource at some point. In that case, you care trying to cast a BindingSource to a DataTable. Try something like:
Dim bs as BindingSource = dgvMainLookUp.DataSource
Dim dt as DataTable = bs.DataSource
You might need a cast but I think it will work as written.
Upvotes: 0