Answered by:
DataGridView on a .rdlc report vb2005

Question
-
Hi
Is it possible to put a datagrid on a report,or to pass the data, the datagridview contains ,to a table on a report?
I have a datagridview1.The source of it is a dataset. An sql made dataset. What is the simpliest way to make a report from it?
thanks
Tuesday, August 12, 2008 9:52 PM
Answers
-
ok, the .rdlc file is just an xml file. And using the report designer in VS writes the xml for you.
So, the reason I recommended the dataset designer is because this will simplify things for you greatey.
Each .rdlc file stores information about the datasources it expects.
Let me see if I can do this step by step for you.
First, I would add a dataset to my solution. You can do this by rightclicking your solution, choose add new item, and choose dataset.
I'd name the dataset "ds16" (I'm naming it this to match your example") and click ok.
then the dataset appears in my solution explorer. Double click the dataset and now your in the designer for it.
It's actually a very simple thing, while it can be very powerful, were not concerned with that, we are just using it as a means to an end.
Now right click in the designer area and choose "Add" then choose "Datatable"
It will add a table named "DataTable1" most likely. We want to change the name to match the one in your example.
So call the table "kategoria"
Now we need to add columns to this table that match the names of the columns you actually have in the real kategoria datatable.
So just right click the datatable and choose "Add" then choose column. It will add a column named "Column1". Change the name of this column to match the name of a column that's in the real kategoria table.
Repeat this column adding and naming until you've added all the fields you have in the real Kategoria table. And make sure you check the case of each letter, as the reports are case sensitive.
Once you have the datatable, with all the properly named columns, save the dataset.
There are ways you can drag and drop database objects into the dataset designer to simplify all this, but that's a discussion on it's own, and if you want to do that I'd have to recommend you google how to use the "Server Explorer" window.
Ok, so you've basically created a datatable within a dataset for the sole purpose of using it in the design of your .rdlc file.
Open your report to the designer, once it's open, on the top menu bar, you should see "Report". Click it, and choose datasources. Click the drop down on datasources and you should have a choice for "ds16_kategoria". Choose that and click add to report. Sometimes it can take a moment to add to the report, once it's listed in the "Report data sources:" box, click ok.
Now, on your report, i'll assume you have a table.
A table can be linked directly to one datasource. If you highlight your table, and look at the properties window, there should be a property called "DataSetName". you want to set this to "ds16_Kategoria". It should be available as a drop-down choice if you've added the datasource correctly.
once you've completed this, go to your table, in any of the "detail" row cells, right click and choose "Expression"
This will bring up the "Edit Expression" box. On the bottom left you'll have a box with several choices, and one of those choices should be "Fields(ds16_kategoria)"
click this, and you'll see a list of all your columns you created earlier in the dataset designer. Just double click a field and it will add it to the expression.
The dataset you created earlier has no further use, you can remove it from your solution if you like. As I mentioned earlier, the .rdlc fiile will store all information about the datasource within itself.
If you need more help, or anything I said isn't clear, feel free to ask. I just ask that you be as specific as possible.
Living my life at 123mph in 11.15 seconds- Marked as answer by Tibore Thursday, August 14, 2008 10:32 PM
Thursday, August 14, 2008 8:22 PM
All replies
-
Hi Tibore,
You cannot use a datagrid control within your report viewer control. However, you can use the Table report item to display information similar to a data grid. Hope that answers your initial questions.
It looks like you are new to the Report Viewer control and Reporting Services, you might want to get some information on report creation.
Report Viewer Control website: http://www.gotreportviewer.com
Book for report authoring and reporting: Microsoft® SQL Server 2005 Reporting Services
Link to videos: http://www.trainingspot.com/VideoLibrary/SQL/SSRS_101.aspx
Brad Syputa, Microsoft Reporting Services This posting is provided "AS IS" with no warranties.- Proposed as answer by JakeFortuna Thursday, May 1, 2014 12:50 PM
Wednesday, August 13, 2008 4:55 PM -
I read it all before and didn't get any help. Yes I'm new to the report and stuff and I really wan't to learn these features. I'm making my graduate work of it and I have less than a month....ok.
I think about the following...
I put a simple table on the report.
I know that if I drag the field from the dataset ,it will display all the rows of the table.
In the table texbox is "=Fields!FirstName.Value" or what ever...
Now
If I make the dataset manually like
dim ds as new datatset
dim da as .......
....
----------------------------------
sql = "SELECT * FROM tablename"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds16, "table_new")
Now my table is "table_new".
What should I type in the report's table's textbox to get the values of this table(table_new),or get the fields of the new table.
If I write "=Fields!column_name_of_table_new.Value" ,is not good becouse it doesn't know what that is.
I really need help with this...
Wednesday, August 13, 2008 6:28 PM -
Hi tibore, your on a good track here, stick with it. Let me see if I can help you out.
Go ahead and fill the dataset manually...that's a good idea. The trick is how to design the report.
What I like to do when designing a report, to make it easy on myself, I use the dataset designer. I just add a dataset to my project, then I either auto-create a table from a stored procedure, or whatever. Or I manually create a table myself within the dataset designer.
Once this is created, you can easily access it for creating your report, and drag and drop the field names.
I do not use this dataset for anything else. It's not linked to the report, it's not referenced in code. It's merely a simple tool for use when designing the report.
instead, i do exactly what your doing, and I fill my dataset at run time. The trick is my datasources for my reports all use the same name.
The name of the dataset that you fill, or the tables within it, is of no consequence at runtime. This only matters at design time. To make life easy on myself, every report I create is given a very generic dataset and table name.
Like "ReportDataSet" for the dataset name and
"ReportData1" for the first table, and "ReportData2" for the next table, and so-on.
So, when it comes to actual run-time, my reports are always looking for a datasource of the same name. This avoids me having take time/code to make sure my datasource names match the names of the reports I'm creating. And personally I could care less about the datasource names, it's not something I need in my solution.
So, at runtime, you've created a dataset. next you tell your reportviewer what .rdlc file to use, and then you provide the datasources needed for this report.
To provide the datasource, this is what you do
Dim
customReportData As New ReportDataSource
customReportData.Name =
"ReportDataset_ReportData1" 'This is where the name has to match the name the report expects customReportData.Value = ReportDataSet.Tables(0)
ReportViewer1.LocalReport.DataSources.Add(customReportData)
ReportViewer1.LocalReport.Refresh()
Living my life at 123mph in 11.15 secondsWednesday, August 13, 2008 6:43 PM -
Hi Blast2hell!
Sorry I didn't read your answer yesterday...
You seem to know a lot about creating a report….it’s gooood. :-)
I’m not quite familiar with the dataset designer. It would totally confuse me.
So my code looks like this so far, and I think it works too.
Private Sub ReportViewer1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReportViewer1.Load
Dim customReportData As New ReportDataSource
customReportData.Name = "ds16_kategoria"
customReportData.Value = ds16.Tables("kategoria")
ReportViewer1.LocalReport.DataSources.Add(customReportData)
ReportViewer1.LocalReport.Refresh()
End Sub
ds16 is my dataset and kategoria is my table name
The next step is to tell the table on the report, what should he display, isn’t it?
How can I do that?
Many many thanks for your help!!!!
Thursday, August 14, 2008 8:03 AM -
For like 10 hours I have been killing myself to make this work. My brain is like in 100 pieces.
I still cannot figure out how does the table on the report know about my datatable "kategoria". Ok I know that it knows about the "kategoria", how does he know about the data in it??
I understad that we are giving the data source manually. But how are we putting the data (the table "kategoria" contains) in the report table???
Neeeed you Blast2heeeeeell!!!Thursday, August 14, 2008 7:52 PM -
ok, the .rdlc file is just an xml file. And using the report designer in VS writes the xml for you.
So, the reason I recommended the dataset designer is because this will simplify things for you greatey.
Each .rdlc file stores information about the datasources it expects.
Let me see if I can do this step by step for you.
First, I would add a dataset to my solution. You can do this by rightclicking your solution, choose add new item, and choose dataset.
I'd name the dataset "ds16" (I'm naming it this to match your example") and click ok.
then the dataset appears in my solution explorer. Double click the dataset and now your in the designer for it.
It's actually a very simple thing, while it can be very powerful, were not concerned with that, we are just using it as a means to an end.
Now right click in the designer area and choose "Add" then choose "Datatable"
It will add a table named "DataTable1" most likely. We want to change the name to match the one in your example.
So call the table "kategoria"
Now we need to add columns to this table that match the names of the columns you actually have in the real kategoria datatable.
So just right click the datatable and choose "Add" then choose column. It will add a column named "Column1". Change the name of this column to match the name of a column that's in the real kategoria table.
Repeat this column adding and naming until you've added all the fields you have in the real Kategoria table. And make sure you check the case of each letter, as the reports are case sensitive.
Once you have the datatable, with all the properly named columns, save the dataset.
There are ways you can drag and drop database objects into the dataset designer to simplify all this, but that's a discussion on it's own, and if you want to do that I'd have to recommend you google how to use the "Server Explorer" window.
Ok, so you've basically created a datatable within a dataset for the sole purpose of using it in the design of your .rdlc file.
Open your report to the designer, once it's open, on the top menu bar, you should see "Report". Click it, and choose datasources. Click the drop down on datasources and you should have a choice for "ds16_kategoria". Choose that and click add to report. Sometimes it can take a moment to add to the report, once it's listed in the "Report data sources:" box, click ok.
Now, on your report, i'll assume you have a table.
A table can be linked directly to one datasource. If you highlight your table, and look at the properties window, there should be a property called "DataSetName". you want to set this to "ds16_Kategoria". It should be available as a drop-down choice if you've added the datasource correctly.
once you've completed this, go to your table, in any of the "detail" row cells, right click and choose "Expression"
This will bring up the "Edit Expression" box. On the bottom left you'll have a box with several choices, and one of those choices should be "Fields(ds16_kategoria)"
click this, and you'll see a list of all your columns you created earlier in the dataset designer. Just double click a field and it will add it to the expression.
The dataset you created earlier has no further use, you can remove it from your solution if you like. As I mentioned earlier, the .rdlc fiile will store all information about the datasource within itself.
If you need more help, or anything I said isn't clear, feel free to ask. I just ask that you be as specific as possible.
Living my life at 123mph in 11.15 seconds- Marked as answer by Tibore Thursday, August 14, 2008 10:32 PM
Thursday, August 14, 2008 8:22 PM -
Hi
I did everything like you wrote , but my report acts like my table has no data in it.
I did every step with two tables to be sure I didn't do something wrong...I didn't.
Is there anything I have to type in the reportviewer's code to fil the table with data???
Private Sub Form7_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
"maybe here"
Me.ReportViewer1.RefreshReport()
End Sub
Private Sub ReportViewer1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReportViewer1.Load
"or here"
End Sub
Thursday, August 14, 2008 10:25 PM -
I had to fill it...
....and it WOOOOOOOOOOOOOOOOORKS!!!!!!!!!!!!!!!!!
Thanx everything.....I owe you a lot.
Thursday, August 14, 2008 10:32 PM -
np, glad you got it working.
Living my life at 123mph in 11.15 secondsThursday, August 14, 2008 10:56 PM -
hii guys can you tell me how you fill it the dataset.
thanksFriday, February 20, 2009 8:00 AM -
there are lots of ways to fill a dataset, I recommend you read up on ADO.NET.
Grab a good book or two and read up on datasets and datatables. Probably 1000 simple tutorials on the internet showing how to put data into your datatable.
Living my life at 123mph in 11.15 secondsFriday, February 20, 2009 2:43 PM