Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 984
  • Last Modified:

Populating a DataTable from a BindingSource

Hi, I'm using VB 2005, WinForms. I have several DataGridViews in my application and I populated them with a BindingSource. That all works well.

I now need to create some reports using ReportViewer, but ReportViewer gets its feed from a DataSet, which in turn contains a DataTable.

What I'd like to do is use my BindingSouce to populate my Report's DataTable.

Something like this (although I know this won't work)...

DataTable1.DataSource = bs   << I know this is not correct, but its what I'd like to do.

Is there a way to do this, or do I need to simply poplate a new DataTable from a DataAdapter, CommandBuilder...etc? (I'd really dislike redoing all that)

Thanks for the help and advice,
Fulano
0
Mr_Fulano
Asked:
Mr_Fulano
  • 2
  • 2
  • 2
  • +1
1 Solution
 
rgn2121Commented:
I have never used a bindingsource, but you might try something like this if you are sure of what the bindingsource contains...

Dim dt As DataTable = DirectCast(bs.DataSource, System.Data.DataTable)
0
 
drypzCommented:
Hi! Do it something like this.

DataTable dataTable = bs.DataSource as DataTable;
0
 
rgn2121Commented:
fyi...I did not run through this to see if there would be any issues or if it would even work...
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
drypzCommented:
Sorry didn't seen the other comment.
0
 
VBRocksCommented:
Well, one thing to keep in mind is that when you create a DataSet and fill it from the DataBase, then the loaded DataSet exists in memory:

    DataSet in memory.

When you create a BindingSource, and set it's DataSource to the DataSet that you have already created and loaded, and is in memory, Then the BindingSource is simply pointing to the existing DataSet that is in memory; it's not creating and using a copy of it.  

    DataSet in memory <- BindingSource


So, you can actually use the DataSet itself as the DataSource for the Report.

0
 
Mr_FulanoAuthor Commented:
Hi VBRocks, you bring up a good point. That's one of the reasons I wanted to use my BS rather than fill another DataSet just for the report. I actually create my DataSets and DataTables programmatically. I don't use the Wizard. However, for use with ReportViewer its easier to create a "dummy" DataSet and then add DataTables to it, to then be used with in Report. I needed a way to populate my DataTable with the most recent information available, which in y case is the BS.

Thanks for the comment,
Fulano
0
 
Mr_FulanoAuthor Commented:
Very good suggestion. This works well.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now