
SetDataSource not working with Crystal Reports .NET in VB.NET
Below is the code I use to show a report through a report viewer
control. It seems to work fine, except that it displays all the data
in the selected view, rather than just the data defined by the "where"
clause as I've typed below. I've tried about a million different
combinations of properties and methods, none of which make a
difference, and the help files seem to indicate that I'm doing this
right. Can someone tell me why the "setdatasource" doesn't seem to be
doing its job? Thanks,
Andrew
Dim myReport As New
CrystalDecisions.CrystalReports.Engine.ReportDocument()
Dim objTable As CrystalDecisions.CrystalReports.Engine.Table
Dim objLoginInfo As CrystalDecisions.Shared.TableLogOnInfo
Dim dsNetwork As New DataSet()
sReport = System.Configuration.ConfigurationSettings.AppSettings("report_path")
& "\myReport.rpt"
Dim strNetworkSQL As String = "select * from myView where
season_id = " & g_yearID
Dim daNetwork As New SqlDataAdapter(strNetworkSQL, g_oConn)
daNetwork.Fill(dsNetwork)
myReport.Load(sReport)
myReport.SetDataSource(dsNetwork)
For Each objTable In myReport.Database.Tables
objLoginInfo = objTable.LogOnInfo
objLoginInfo.ConnectionInfo.Password = "xxx"
objTable.ApplyLogOnInfo(objLoginInfo)
Next
Dim frmReport As New frmReportPreview()
frmReport.ReportViewer.ReportSource = myReport
frmReport.ReportViewer.DisplayGroupTree = False
Cursor.Current = Cursors.Default
frmReport.ShowDialog()