How to pass data from DataGridView to table in ReportViewer without Database or Dataset - vb.net

I have a few DataGridView tables which user fills (I don't use any Dataset or Database here).
I need to pass them to ReportViewer, I want exact the same tables in report as in a form, no changes at all.
I tried something like this, but it's not working:
Dim rds As New ReportDataSource("rds1", Form1.dgv1.DataSource)
Me.ReportViewer1.LocalReport.DataSources.Add(rds)
and in report1.rdlc added a table and set it dataset name to rds1 but it generates error
The table ‘table1’ refers to an invalid DataSetName ‘rds1’.
So I guess I need to make a DataSet from my DataGridView tables.
How would you suggest me to do that? Otherwise, is there any simpler way to pass the table to report?

You should add a DataSet to your report .rldc Data Sources list and drag and drop the columns into your report element (table, tablix, list etc.)
Remember you can add any kind of object from your project to your report as Data Source (basically any Public Class you create). The imported names and types will be taken from the class properties.

Related

vb.net create tabpages and datagridview from list exported from SQL

Just after some ideas on the best way to create additional tabpages dynamically within a tabcontrol and also to then add the relevant data on each tab with a datagridview.
The tabcontrol will always exist, but I'm not sure whether to initially create the additional tabpages first by identifying the distinct data in SQL, and then run a further script to extract the data, which then needs to be added to the datagridview, or whether I can use vb.net to create the distinct tabpages and add the data from one table, as below.
I can add another tabpage dynamically but not sure the best way to do it for a list, that is extracted from SQL.
Hope that makes sense. Thanks
TabCode
TabName
DataName
DataType
1
One
Test Name
Text
1
One
Test Date
Date
2
Two
Test Value
Value
I've managed to create new tabpages, but only single instances as not sure how to create them from a list extracted from SQL. I'm then struggling to add the data to the relevant datagridview, which I envisage would be created with a name linked to the tabpage name.

Does VS 2017 allow two datasets for an rdlc report?

I have a framework for my applications that hold reports that are printed from the application. I have one report that I'm trying to add a second dataset to but I keep getting the error "A data source instance has not been supplied for the data source 'DataSetTwo'". Is it impossible to add a second dataset to a report?
The reason I'm adding a second data source is I have one that will populate nearly all information on the report and then the second is going to be used for a tablix in the report. I can't use the first dataset because for some reason the group by is not working on the SQL statement so I'm going to add a new dataset with less fields so the group by isn't a problem.
The error
A data source instance has not been supplied for the data source 'DataSetTwo'
indicate you had not supply the data source.
When you generate the report, did you supply the second dataset?
It should look something like this:
ReportViewer.LocalReport.DataSources.Clear();
ReportDataSource rd1 = new ReportDataSource("DataSetOne", dataset1);
ReportDataSource rd2 = new ReportDataSource("DataSetTwo", dataset2);
ReportViewer.LocalReport.DataSources.Add(rd1);
ReportViewer.LocalReport.DataSources.Add(rd2);
ReportViewer.LocalReport.Refresh();

Binding DataSet to RDLC

I am creating rdlc report(not using reportviewer, using report template). I have a business class which has a code for getting dataset by calling stored procedure. I am binding that dataset to rdlc report using ReportDataSource class. How to access this dataset in design?
In rdlc xml file, I tried to add dataset and it fields, it works fine if the columns are constant. I have a dataset it returns a datatable which has variable number of columns depending on user selection, will get to know number of columns at run time, that dataset I want to assign to table or any control in rdlc design. How can I do that?
Thanks,
Megha

Substitute one table for another at runtime

I have 9 tables with state information in them. They all have the same field names. I have a Crystal Report that is based on one of them. I want the user to be able to select a state and change the Crystal Report to use that table instead of the one it was based on.I mean when user select text in combo box and then click on "OK" then report show (using only one rpt for all the tables of same fields).
How do I do that in VB.Net?
Could you base the Report on a Stored Procedure and pass in a parameter so the Stored Procedure knows which table you want the data from?
I remember trying to get a Crystal Report (v2005) to switch database source from the one it was designed against and that wasn't easy - every table had the connection details in it if I recall correctly! (maybe changing tables is easier though)
It's not easier but if the tables have the same structure you should be able to do it. But you should create a new Document for it and call SetDataSource for your new table. After this you can set the document as ReportSource to your viewer.

How update a SQL table from a modified datatable?

I used the DataSet Designer to create FTWDataSet which holds the AlarmText table from a SQLExpress database. This far my form contains ONLY Datagridview1. The code below successfully shows the contents of the AlarmText table plus the one added checkbox column (which I will populate with display-only data, and is not an issue here).
Dim ta As New FTWDataSetTableAdapters.AlarmTextTableAdapter
Dim dt As New FTWDataSet.AlarmTextDataTable
ta.Fill(dt)
DataGridView1.DataSource = dt
'create a new Bool column in the datatable
dt.Columns.Add("NewCol", (New Boolean).GetType)
What else do I need to do to use the DataGridView to edit and save values in the AlarmText table?
Here's a brief MSDN walkthrough on this topic.
Some notes:
You shouldn't need a binding source to persist changes back to the database.
To make the table adapter accessible to other procedures in your form, make it a form-scoped (a.k.a. member) variable instead of method-scoped, as in your example.
If you created your Dataset using the Dataset Designer, and you're fetching your original data from anything more than a simple table or view, then your adapter won't know how to update anything in the original database. You have to manually configure the UPDATE command in this situation. For reference, see the TableAdapter Update Commands section in the above link.
I should also mention that I avoid TableAdapters in ADO.Net like the plague. In theory they're very convenient and powerful. In practice, many of them (especially the one for the Oracle provider) are buggy, and if they don't work exactly right you're totally screwed.
If you're pulling from just one underlying table, the adapter should work fine (so ignore my nihilistic advice for the time being). It may be that adding an additional column in code will breaks the adapter (since there's no corresponding column in the database table).