Hi Dom,
Yes, ASPX pages are for .Net, but I think this code will work with ASP. The idea behind this is to "push-down" the record selection to the database server. In my case, this was critical because one of my tables has 1.5 million rows. Here are the steps I am using:
1) Create a web form where the user can enter the parameters. On this form, you will need a command button to set the session variables and then call the next web form that contains the Crystal Report Viewer. You can create a session variable (e.g., "CTARegion") with any name like this:
Session("CTARegion") = txtRegion.Text
2) Create the report using the fields needed from the various table(s).
3) Create the web form that will hold the Crystal Report Viewer. In the page load event, I placed the following code:
If Not Page.IsPostBack Then
'Retrieve parameter value entered in web form
' CountySelectRegion.aspx
Dim strRegion As String
strRegion = Session("CTARegion".ToString)
' connect to Access database
Dim sConnString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" + MapPath("CDR2004.MDB") & ";" & _
"User ID=Admin;" & _
"Password="
Dim oOleDbConnection As OleDb.OleDbConnection = New OleDbConnection(sConnString)
oOleDbConnection.Open()
' build the select statement
Dim selectString As String = "select * from COUNTY where CTA_RegionID = '" & strRegion & "'"
Dim tempOleDbDataAdapter As New OleDbDataAdapter(selectString, oOleDbConnection)
Dim dsCountyRegion As New DataSet
tempOleDbDataAdapter.Fill(dsCountyRegion, "County")
Dim cr As CountyRegionRpt
cr = New CountyRegionRpt
cr.SetDataSource(dsCountyRegion)
CrystalReportViewer1.ReportSource = cr
End If
4) Normally, the Crystal Report Viewer is bound to the report (through Bindings), but in this instance you should
not do this.
HTH, ![[pc2] [pc2] [pc2]](/data/assets/smilies/pc2.gif)
Randy Smith, MCP
California Teachers Association