Crystal Reports Parameters in ASP.NET

danabare

Member
Joined
Jul 1, 2003
Messages
8
I am trying to pass a parameter to a Crystal Report. If I remove the parameter and alter the code appropriately, the report displays fine. Most of the code I am using below is copied directly from the online help within VS.NET but I am getting the error message, "Missing parameter field current value."?? Can someone please help me?

Thanks,
Dana


Imports CrystalDecisions.Shared

Public Class MoviesRpt
Inherits System.Web.UI.Page
Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer

#Region " Web Form Designer Generated Code "

This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
CODEGEN: This method call is required by the Web Form Designer
Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim paramFields As New ParameterFields()
Dim paramField As New ParameterField()
Dim discreteVal As New ParameterDiscreteValue()

paramField.ParameterFieldName = "prm_sort_order"

discreteVal.Value = "C"
paramField.CurrentValues.Add(discreteVal)
paramField.ReportName = "C:\Inetpub\wwwroot\Movies\CR_MoviesRpt.rpt"

paramFields.Add(paramField)

CrystalReportViewer1.ReportSource = "C:\Inetpub\wwwroot\Movies\CR_MoviesRpt.rpt"
CrystalReportViewer1.ParameterFieldInfo = paramFields
CrystalReportViewer1.DataBind()
End Sub

End Class
 
Hey dana, I was going through a lot of the same problems and finally got mine to work, I was using this website: http://www.crystalreportsbook.com/
All the sample code is in vb.net so I had to convert it to c# heres a listing of the code i used in my code behind:

protected System.Web.UI.WebControls.Label lblMessage;
protected CrystalDecisions.Web.CrystalReportViewer crvTrx;

private void Page_Load(object sender, System.EventArgs e)
{

ReportDocument oRpt = new ReportDocument();
oRpt.Load(@"D:\wwwroot\Maintenance\images\beta_trx.rpt");
int intMaintenance_ID = Int32.Parse(Request["ID"].ToString());

ParameterValues paramVals = new ParameterValues();

ParameterDiscreteValue discreteVal = new ParameterDiscreteValue();
discreteVal.Value = intMaintenance_ID;
paramVals.Add(discreteVal);

oRpt.DataDefinition.ParameterFields[ "Maintenance_ID" ].ApplyCurrentValues ( paramVals );

int intSuccess = 0;

foreach(CrystalDecisions.CrystalReports.Engine.Table tbl in oRpt.Database.Tables)
{
CrystalDecisions.Shared.TableLogOnInfo logOn = tbl.LogOnInfo;

logOn.ConnectionInfo.ServerName = "sqlserver";
logOn.ConnectionInfo.DatabaseName = "dbname";
logOn.ConnectionInfo.UserID = "userid";
logOn.ConnectionInfo.Password = "password";

tbl.ApplyLogOnInfo(logOn);

if (!(tbl.TestConnectivity()))
{
intSuccess = 2;
}
else
intSuccess = 1;


}

switch(intSuccess)
{
case 1:
try
{
crvTrx.ReportSource = oRpt;
crvTrx.DataBind();
crvTrx.Visible = true;
}
catch(CrystalDecisions.CrystalReports.Engine.EngineException crystExe)
{
string strEx = crystExe.ToString();
lblMessage.Text = "The Following error occured:<br/>" + strEx;
crvTrx.Visible = false;
}
break;
case 2:
crvTrx.Visible = false;
lblMessage.Text = "There was an internal error with the Logon Credentials provided to the report";
break;
case 0:
crvTrx.Visible = false;
lblMessage.Text = "There was an internal error with the report.";
break;
}

}
 
Hey thanks for replying!! I apologize for not posting that I had figured out a solution myself! By the time I did, I forgot about this post. I had to look a long time myself to find an answer. :) I used this example on ASP Alliance web site to get mine going:
http://www.aspalliance.com/articles/CrystalReportVSNet.aspx

I had to tweak it some because I was using a Stored Procedure to retrieve the data but finally got it all working properly. :D I simply put text boxes on the web form for the parameters and passed them to the SP in the code behind. I dont have exact code on this computer to send but, is real close to the example above. If anyone needs the exact VB.NET code for doing this with an SP let me know and I can add it to this thread later.

Thanks again,
Dana
:cool:
 
More headaches

O.k Im passing data, login info, etc. Now for some reason its not hiding my subreports when they are empty, was before but not now. Have you seen anything about doing this from the code behind? I cant find any info on it.

Also, im interested in seeing the sproc code, how hard was that to do?
 
Back
Top