Thanks for the quick reply. I appreciate your time.
After more testing, I found that it was actually passing the dataset, but the Report Selection Criteria from the Designer was still executing.
I stripped out the Record Select statement and the Grouping out of the Report Designer and put the report back on the share and then the code to pass the dataset works.
Now I have to read up on passing/maniplulating Formula Fields, Parameters and RecordSelection formulas.
Private Sub cmdPrintPreview_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdPrintPreview.Click
Dim strReportName As String = " "
Dim strDisplayedReportName As String = " "
Dim strReportPath As String = " "
Dim SelItem As ListView.SelectedListViewItemCollection
Dim strStoredProcName As String = " "
Dim crpt As New ReportDocument
‘frmReportsViewer has CrystalReportsViewer1
Dim objfrmReportViwer As New frmReportsViewer
Dim rptDataSet As New DataSet()
Dim rptDataAdapter As New SqlDataAdapter()
Dim rptcommand As New SqlCommand()
Dim rptconnect As New SqlConnection()
'Check to see if user has selected a displayed report name from the list, then get the actual report name
Try
SelItem = Me.lvReportNames.SelectedItems
If Me.lvReportNames.SelectedItems.Count = 0 Then
MessageBox.Show("Please select Report and then click Print.")
Exit Sub
Else
strDisplayedReportName = RTrim(SelItem(0).SubItems(0).Text)
End If
strReportName = RTrim(GetReportName(strDisplayedReportName))
Catch ex As Exception
MessageBox.Show("Report Selection error. cmdPrintPreview_Click")
MessageBox.Show(ex.ToString, C_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error)
Call Close()
End Try
strStoredProcName = "usp_" & strReportName
Try
rptconnect = New SqlClient.SqlConnection(gstrCNNString)
rptcommand = New SqlClient.SqlCommand(strStoredProcName, rptconnect)
With rptcommand
.Connection = gcnnSQLConnection
.CommandType = CommandType.StoredProcedure
.CommandText = "usp_" & strReportName
End With
rptconnect.Open()
rptDataAdapter.SelectCommand = rptcommand
rptDataAdapter.Fill(rptDataSet, "ReportQuery")
rptconnect.Close()
‘Returns the correct number of rows from SQL Server stored proc
MessageBox.Show(rptDataSet.Tables.Item("ReportQuery").Rows.Count)
Catch ex As Exception
MessageBox.Show("Data retrieval error. cmdPrintPreview_Click")
MessageBox.Show(ex.ToString, C_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error)
Call Close()
End Try
'Check to see if the data retrieval returned rows.
Try
If rptDataSet.Tables.Item("ReportQuery").Rows.Count = 0 Then
MessageBox.Show("No data returned for your report. Check report paramters and expand criteria if applicable.")
'Me.Close()
'Me.Dispose()
Exit Sub
Else
' Data found run the report
strReportPath = c_REPORTNAMEPATH & RTrim(strReportName) & ".rpt"
If Not IO.File.Exists(strReportPath) Then
MessageBox.Show("No Path")
End If
‘It loads the report from a shared dir correctly
crpt.Load (strReportPath)
crpt.Refresh()
‘Doesn’t load the dataset into the report.
crpt.SetDataSource(rptDataSet)
rptDataSet.Dispose()
rptDataAdapter.Dispose()
With objfrmReportViwer
.CrystalReportViewer1.ReportSource = crpt
.Refresh()
.Show()
End With