Hello,
this is my code in C# for printing a Crystal Report.
protected void Print(object sender, EventArgs e)
{
ImageButton lnkRowSelection = (ImageButton)sender;
ReportDocument cryRpt = new ReportDocument();
string[] commandArgs = lnkRowSelection.CommandArgument.ToString().Split(new char[] { ',' });
string idno = commandArgs[0];
string company = commandArgs[1];
try
{
if (lnkRowSelection.CommandArgument.ToString() == null)
Response.Redirect("Default.aspx");
else
{
if (company == "True")
cryRpt.Load(Server.MapPath("~/Reports/rep1.rpt"));
else
cryRpt.Load(Server.MapPath("~/Reports/rep2.rpt"));
if (lnkRowSelection.CommandArgument.ToString() != null)
{
cryRpt.SetParameterValue("@idno", idno);
cryRpt.SetParameterValue("Office", agr.getOffice());
cryRpt.PrintToPrinter(2, true, 1, 2);
}
}
}
Rep1 and Rep2 were created using Report Wizard and are binded to a sproc. Idno is a parameter for the sproc and office is a second parameter i added to the report.
I use integrated connection (even though I tried SQL authentication and I still get the same errors)
The problem is that I get the error "The types of the parameter field and parameter field current values are not compatible" but only when I use the published version. If I run the application through Visual Studio the report is printing just fine.
I'm using Windows Server 2012 R2, IIS 8.5 , Crystal Reports 13, .NET Framework 4.5.2
So far I've tried the following:
Checked that both parameters are data type String and getting string as input.
Checked that there are no null values as input.
Change .rpt properties to Content
Added asp_client to my application folder.
Tried printing a report without parameters, even though I don't get the error the report didn't print either.
Any ideas what might be wrong?
Thank you in advance.