zipnotic
asked on
Datasource for Report Viewer error when loading report
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.Te xt
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_P K = " + assigned + ")"
Try
If sql.State <> ConnectionState.Open Then sql.Open()
cmd.ExecuteNonQuery()
da.SelectCommand = cmd
da.Fill(Me.ReportEvent.v_I ncident)
' da.Fill(ds, "v_Incident")
Catch ex As Exception
MsgBox("Error Connecting to database.", MsgBoxStyle.Critical, "Error Alert!")
End Try
ReportViewer1.ProcessingMo de = Microsoft.Reporting.WinFor ms.Process ingMode.Lo cal
Me.ReportViewer1.LocalRepo rt.ReportE mbeddedRes ource = "Search.Report3.rdlc"
ReportDataSource1.Name = "v_Incident"
ReportDataSource1.Value = ds.Tables("v_Incident")
Me.ReportViewer1.RefreshRe port()
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?
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.Te
cmd.CommandText = "SELECT dbo.v_Incident.*, dbo.v_IComment.* FROM dbo.v_IComment INNER JOIN dbo.v_Incident ON dbo.v_IComment.Incident_FK
Try
If sql.State <> ConnectionState.Open Then sql.Open()
cmd.ExecuteNonQuery()
da.SelectCommand = cmd
da.Fill(Me.ReportEvent.v_I
' da.Fill(ds, "v_Incident")
Catch ex As Exception
MsgBox("Error Connecting to database.", MsgBoxStyle.Critical, "Error Alert!")
End Try
ReportViewer1.ProcessingMo
Me.ReportViewer1.LocalRepo
ReportDataSource1.Name = "v_Incident"
ReportDataSource1.Value = ds.Tables("v_Incident")
Me.ReportViewer1.RefreshRe
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?
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.DataTa ble1). 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.Te xt
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.Dat aTable1) wants a dataset fill not table fill
da.Fill(ds, "DataTable1")
ReportViewer1.ProcessingMo de = Microsoft.Reporting.WinFor ms.Process ingMode.Lo cal
Me.ReportViewer1.LocalRepo rt.ReportE mbeddedRes ource = "Search.Report3.rdlc"
Me.ReportViewer1.LocalRepo rt.DataSou rces.Add(N ew Microsoft.Reporting.WinFor ms.ReportD ataSource( "ReportEve nt_DataTab le1", ds.Tables("DataTable1")))
Me.ReportViewer1.RefreshRe port()
Catch ex As Exception
MsgBox("The following error prevented the report from loading:" + vbCrLf + ex.Message.ToString, MsgBoxStyle.Critical, "Error Alert!")
End Try
cmd.Connection = sql
cmd.CommandType = System.Data.CommandType.Te
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.Dat
da.Fill(ds, "DataTable1")
ReportViewer1.ProcessingMo
Me.ReportViewer1.LocalRepo
Me.ReportViewer1.LocalRepo
Me.ReportViewer1.RefreshRe
Catch ex As Exception
MsgBox("The following error prevented the report from loading:" + vbCrLf + ex.Message.ToString, MsgBoxStyle.Critical, "Error Alert!")
End Try
ASKER
Awesome help.
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.LocalRepo
So you're entire code section should look like this code snippet.
Open in new window