Link to home
Start Free TrialLog in
Avatar of geraintcollins
geraintcollins

asked on

Opening a crystal report at a specific record (ASP.Net with VB.Net) linked to SQL backend

Hi,

I have a crystal report that is linked to a sql server 2000 database table via OLE DB (ADO) what is the best practice for opening the report to show only a specific record (essential that the user cannot see other records)

Is it:
1) Open the report and pass a parameter for the key field. If yes could you please provide an example.
2) Create a dataset with just the record relating to the key field and set the reports datasource to the dataset. This is working for the attached code but if there is a simpler way then I'd be happy to use it rather than having to do this for every report I need to open.
3) Some other way


Dim reportPath As String = Server.MapPath("Test123.rpt")
        Dim myConnection As New SqlConnection
        myConnection.ConnectionString = ConnectionStrings("MyDB").ConnectionString
        Response.Write(myConnection.ConnectionString)
        Dim MyCommand As New SqlCommand()
        MyCommand.Connection = myConnection
        MyCommand.CommandText = "Select * from TableName where FPlanID = " & intPlanID 'session variable
        MyCommand.CommandType = CommandType.Text
        Dim MyDA As New SqlDataAdapter()
        MyDA.SelectCommand = MyCommand
        Dim myDS As New DataSet()
        Dim rpt As New ReportDocument
        MyDA.Fill(myDS, "TableName")
        rpt.Load(reportPath)
        rpt.SetDataSource(myDS)
        rpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, False, "ExportedReport")

Open in new window

Avatar of geraintcollins
geraintcollins

ASKER

I'm having an issue with option 2 as the report now contains sub reports so I'm getting a login error when the report opens as the sub report references a different but related table, hmmm.
Avatar of Bob Learned
I would usually define a RowFilter for a DataTable.DefaultView, and bind to the DataTable.DefaultView.  I would think that you could do that with a Crystal Report.
Could you please provide some sample code for me to look at (asp.net vb). thx.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks