on 08-28-2014 1:24 AM
Hi, Ludek,
I hope it's okay, but I thought it would be better to start a new post about the parameter issue.
To recap, the issue is:
I am writing a Windows application with VS 2012. This application has several reports. There is a particular report that has a parameter that I use as the header. In the Form Load event handler of the form that displays the report, I set the parameter with the line rpt.SetParameterValue(0, strHeader), where rpt is the instance of the report, and strHeader holds whatever I want the header to be.
This was working great. Last week I tweaked the report to and a line feed after the text in a field in the dataset. This had nothing to do with the header. After making this change, when I open the form with the report on it, I am prompted to enter the value for the parameter. I can find no reason for this. I put the line that opens the form with the report on it elsewhere in the application, and was not prompted for the parameter value. This is not an acceptable fix, though. I deleted the contents of the bin folder in the project’s folder, but got the same behavior.
The code I posted was the code that generated the .dll error, not the code working with parameters.
This is the code working with parameters:
Private Sub frmPrintAppointments_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim rpt As New rptAppointments
Dim strHeader as String
' I populate the dataset, ds
strHeader = "All appointments"
rpt.Load()
rpt.SetParameterValue(0, strHeader)
rpt.SetDataSource(ds)
CrystalReportViewer1.Dock = Windows.Forms.DockStyle.Fill
CrystalReportViewer1.ReportSource = rpt
CrystalReportViewer1.Visible = True
End Sub
You said:
Invariably, when you pass a value to the report, and the report prompts anyhow, either the type of the value is incorrect, or the parameter is assigned our of scope, so the engine has no idea it was assigned. Stepping through the code may help determine what is actually happening.
The parameter is of string type. How do you specify the scope of a parameter?
Thanks,
Ralph
Hi Ralph,
try to add CrystalReportViewer1.Refresh
Regards,
Jim
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ralph,
Try this code below. or just get partial code from it.
Public Sub loadReport(ByVal rptHeader As String, ByVal rptFilename As String, ByVal recordselectionformula As String)
'Try
' Dim cryRpt As New ReportDocument
Dim myHeader As CrystalDecisions.CrystalReports.Engine.TextObject
Dim crtableLogoninfos As New TableLogOnInfos()
Dim crtableLogoninfo As New TableLogOnInfo()
Dim crConnectionInfo As New ConnectionInfo()
Dim CrTables As Tables
Dim CrTable As Table
'Declare ReportDocument object and load your existing report
'Make sure that you give the correct path for the document else it will give exception
Dim crReportDocument As New ReportDocument()
crReportDocument.Load(AppDomain.CurrentDomain.BaseDirectory & "\Reports\" & rptFilename & ".rpt")
CrystalReportViewer1.ReportSource = crReportDocument
CrTables = crReportDocument.Database.Tables
Dim crLoc As String
crLoc = strCompany & ".dbo"
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
'Read MachineName\InstanceName,Database details from User interface
'and load them into crConnectionInfo object
crConnectionInfo.ServerName = strDataSource
crConnectionInfo.DatabaseName = strCompany
crConnectionInfo.UserID = strLoginId
crConnectionInfo.Password = strPassword
crConnectionInfo.IntegratedSecurity = False
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
CrTable.Location.Substring(CrTable.Location.LastIndexOf(".") + 1)
Next
'set text value to report textbox object
myHeader = CType(crReportDocument.ReportDefinition.ReportObjects.Item("txtHeader"), CrystalDecisions.CrystalReports.Engine.TextObject)
myHeader.Text = myHeader.Text & rptHeader
crReportDocument.RecordSelectionFormula = recordselectionformula
crReportDocument.ReportOptions.EnableSaveDataWithReport = False
'Refresh the ReportViewer Object
crReportDocument.Refresh()
'CrystalReportViewer1.RefreshReport()
'Bind the ReportDocument to ReportViewer Object
CrystalReportViewer1.ReportSource = crReportDocument
End Sub
When I said scope I was thinking of a scenario where the parameter is being coded in one part of the app and that part is not accessible to the viewer. E.g.; if we'd create a new app where all code is in page load, will we still get the prompt? E.g., pseudocode;
Load report
Log on to the database
Set the parameter
View report
Does that work? If not, can you attach the report - with saved data? (You'll have to rename the rpt to txt, then click on "Use advanced editor" and attach there.
- Ludek
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Ludek,
Your pseudocode is what I'm doing except for logging onto the dB. My report is based on a dataset that I populate through code then pass to the report with rpt.SetDataSource(ds)
If I make the form that shows the report the application start up form, I do not get prompted. However, if I load the form that shows the report from another form (the way my application is supposed to work), I get prompted. I do not understand this because the form load event of the form with the report on it sees the same conditions whether it's opened via another form or is the start up form of the application.
I've attached the report with the dB.
Hi Ralph
There is nothing wrong with the report. The fact that if the code is on one form it works and if you change the app so the load occurs on another form, clearly says that something is being lost going from form 1 to form 2(?).
Sorry, but again my simplifications; New report. Form 1 with a button on it calling form 2. Report code on form2 load or under another button. Does that work?
- Ludek
Hi, Ludek,
I don't understand what's going on. Today I tried it the way it's supposed to work, and got prompted. I made the form with the report on it the start up form, did not get prompted. I set the start up form to what it is supposed to be, ran the application the way it is supposed to be, and the report ran perfectly - no prompting. I made a small change to the code in the form load procedure that did not effect the parameter setting, ran it, and got prompted again. I went through the process above - made the form with the report the start up form, not prompted, set the start up form to what it is supposed to be, not prompted when I ran the report the way it is supposed to be ran.
I made a new form with a new report that only had a field that contained the parameter, did the same procedure above with the same results.
The only thing that I can think of is I'm not Importing the right namespaces on the forms that display the reports. Could this be the problem?
Thanks,
Ralph
Hi Ralph
I admire your patience in this - it's frustrating, I know...
I don't think the import of the assemblies is the issue, though might as well check that. I don't think you are using the InProc RAS SDK, so there should only be four CR assemblies;
crystaldecisions.crystalreport.enfine
crystaldecisions.shared
crystaldecisions.reportsource
crystaldecisions.windows
They all should be of version 13.0.2000.x
Now, this app using datasets, I still want to point my finger at the ds. The ds must precisely match what the report expects. If not, you will get prompts or other issues. And your description sounds sooooo, like this is the issue. E.g.; run once, dc is good, so no logon. Run a second time, minor diff in the dataset, prompt. Perhaps enabling the option "verify on 1st refresh" may help, though it is not the best thing to do, but it is not a critical no, no either. What else... your basic code should only have 4 lines of CR code:
Load report
pass ds to the report
set param
view report
Comment out any other CR code, if there is any. And that is about it for now...
Keeping my fingers crossed,
- Ludek
The report was based on three tables. I created a tableadapter that combines the three tables, and created a new report based on that single tableadapter. It was working fine until I gave the header section a little more vertical room by dragging the section divider down (a cosmetic change). I ran my application, and was prompted again. I made NO changes, ran it again and was not prompted. A funny thing - when I get prompted, the header is the value I set the parameter to in code, not the value I enter at the prompt.
I have attached the code in the form load event.
Ralph
Hello,
I have gone to the Database Expert and checked the links. Whether I populate the dataset with dataadapters or tableadapters, I randomly get prompted for the parameter value. I can enter one or click cancel - and either way, CR uses the value passed in code. I have made a test report that had no dataset at all - it just displayed the parameter value that was passed to it with rpt.SetParameterValue(0, "Hello World"), and I still get prompted at times.
I have decided to create a table with one text field. After deleting the one record, I put what I want as a header in that field. I created a report based on the new table that I use as a sub report in the header of the report that started all of this. No parameters - no prompting.
Ralph
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.