Solved

Datasource for Report Viewer error when loading report

Posted on 2010-09-08
5
1,078 Views
Last Modified: 2013-11-27
Hello,

Using VS2008 vb I'm trying to manually load the datasource for a report with the following code:

 cmd.Connection = sql
            cmd.CommandType = System.Data.CommandType.Text
            cmd.CommandText = "SELECT dbo.v_Incident.*, dbo.v_IComment.* FROM dbo.v_IComment INNER JOIN dbo.v_Incident ON dbo.v_IComment.Incident_FK = dbo.v_Incident.Incident_PK WHERE (dbo.v_Incident.Incident_PK = " + assigned + ")"


            Try
                If sql.State <> ConnectionState.Open Then sql.Open()
                cmd.ExecuteNonQuery()
                da.SelectCommand = cmd
                da.Fill(Me.ReportEvent.v_Incident)
                ' da.Fill(ds, "v_Incident")
            Catch ex As Exception
                MsgBox("Error Connecting to database.", MsgBoxStyle.Critical, "Error Alert!")

            End Try

            ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local
            Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "Search.Report3.rdlc"
            ReportDataSource1.Name = "v_Incident"
            ReportDataSource1.Value = ds.Tables("v_Incident")
            Me.ReportViewer1.RefreshReport()


The Form with the report viewer "ReportViewer" loads but displays a grayed out error where the report should be:
A data source instance has not been supplied for the data source 'ReportEvent_v_Incident'.

As a note I had this working with the built in dataset generator and then took it out to do it manually.  I've been putzing around with the code for hours now so things may have gotten really messed up now.
 Any Ideas?
0
Comment
Question by:zipnotic
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:puffdaddy411
ID: 33633261
Here is what you need to do.  I'm guessing your .XSD file is named "ReportEvent".  In your visual dataset (the .XSD file), right-click > Add > DataTable.  This will create a blank datatable NOT a table adapter.  Name it the exact name of your manual programmatically datatable.  Also, add all of the columns you wish to include in your report.  You are essentially building this as a link from your programmatically created table to your .rdlc report.
 
Now, if you are trying to use a report that you previously built off of a table adapter you created, you will need to change the datasource of that report to this datatable you just built.  If you can't get this to work because it can be quirky, rebuild the report using this newly created datatable in the .XSD file.
 
Now that you have a report linked to your newly created "datatable" (not table adapter) in the .XSD file, you can add this one line of code to what you were attempting.
 

Me.ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("ReportEvent_v_Incident", ds.Tables("v_Incident")))
 
So you're entire code section should look like this code snippet.

            ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local
            Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "Search.Report3.rdlc"
            Me.ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("ReportEvent_v_Incident", ds.Tables("v_Incident"))) 
            Me.ReportViewer1.RefreshReport()

Open in new window

0
 

Author Comment

by:zipnotic
ID: 33636365
Thanks for the tip so far!

Is there a way to automate the column creation in the new dataset?  I Have 104 columns in this View.

I have the new "DataTable1" listed in the Data Sources Window under the Report (along with the old, auto created table).  Now I use the smart tag in the report viewer window to point to the new datatable1?  If so The Report Data Source won't allow a change but the Data Source Instance will.  I would point the Data Source Instance to the new DataTable1 ?

Thanks again

0
 
LVL 5

Accepted Solution

by:
puffdaddy411 earned 500 total points
ID: 33643716
You can export the schema of your programmatically created DS by using this line...
 

DS.WriteXmlSchema("YOURPATH\Test.xsd")
 
Open that XSD file and copy/paste your huge table to your working XSD file in the designer.
 
 
I think I follow what you are asking so I'll address what I am interpreting.  You don't need to specify an RDLC report using the smart tag panel if you are using an embedded RDLC report as you are doing here....
 
 Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "Search.Report3.rdlc"
 
You can leave that smart panel info blank (for ReportEmbeddedResource).  If you are looking to change your report RDLC datasource, do this.  From the RDLC designer screen, go to the "Report" menu at the top and select "Data Sources...".  If your "DataTable1" is in your project XSD, it will show up in the drop down on this window.  Add it and remove your TableAdapter created table.

0
 

Author Comment

by:zipnotic
ID: 33648571
Awesome Help! Best yet for me.  It was the Report menu telling the report to go to the correct data table that did it.  Hard to find what you don't know to look for :)  Also I needed to fill the dataset (da.Fill(ds, "DataTable1)) NOT  da.Fill(ReportEvent.DataTable1).  Code below in case anyone else wants to deviate from the cookie cutter report building process.  Easy once you know how to.  Probably build most reports this way from now on:


            cmd.Connection = sql
            cmd.CommandType = System.Data.CommandType.Text
            cmd.CommandText = "SELECT * FROM [SomeTable] WHERE [PK] = " + PK

            Try
                If sql.State <> ConnectionState.Open Then sql.Open()
                cmd.ExecuteNonQuery()
                da.SelectCommand = cmd
                ' da.Fill(Me.ReportEvent.DataTable1)  wants a dataset fill not table fill
                da.Fill(ds, "DataTable1")
                ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local
                Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "Search.Report3.rdlc"
                Me.ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("ReportEvent_DataTable1", ds.Tables("DataTable1")))
                Me.ReportViewer1.RefreshReport()
            Catch ex As Exception
                MsgBox("The following error prevented the report from loading:" + vbCrLf + ex.Message.ToString, MsgBoxStyle.Critical, "Error Alert!")

            End Try
0
 

Author Closing Comment

by:zipnotic
ID: 33648595
Awesome help.  
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
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…

679 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