Solved

Populating a DataTable from a BindingSource

Posted on 2009-07-06
7
959 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

789 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