Solved

Populating a DataTable from a BindingSource

Posted on 2009-07-06
7
954 Views
Last Modified: 2012-08-14
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
Comment
Question by:Mr_Fulano
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 12

Accepted Solution

by:
rgn2121 earned 500 total points
ID: 24791714
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
 
LVL 13

Expert Comment

by:drypz
ID: 24791717
Hi! Do it something like this.

DataTable dataTable = bs.DataSource as DataTable;
0
 
LVL 12

Expert Comment

by:rgn2121
ID: 24791718
fyi...I did not run through this to see if there would be any issues or if it would even work...
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 13

Expert Comment

by:drypz
ID: 24791721
Sorry didn't seen the other comment.
0
 
LVL 27

Expert Comment

by:VBRocks
ID: 24794560
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
 

Author Comment

by:Mr_Fulano
ID: 24800311
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
 

Author Closing Comment

by:Mr_Fulano
ID: 31600477
Very good suggestion. This works well.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now