将水晶报告导出为PDF会丢失参数值 [英] Exporting crystal report to PDF gives missing parameter values
问题描述
我正在尝试导出水晶报告以便邮寄。我用过:
Hi,
I am trying to export crystal report in order to mail it. I have used :
printbanqoute.ExportToDisk(ExportFormatType.PortableDocFormat, "E:\\ASD.pdf");
然而我收到错误的缺少参数值。
如果不使用ExportToDisc,它可以正常工作。
我使用了4个参数并检查了它们中的每一个它有值,继承人我是如何使用的:
However I get an error the "Missing Parameter Values".
Without using ExportToDisc it works fine.
I have used 4 parameters and checked each one of them it has values, heres how i used :
ParameterFields paramFields = new ParameterFields();
ParameterField paramField = new ParameterField();
ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
paramField.Name = "phoneno";
paramDiscreteValue.Value = BLDashboard.phoneno;
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
paramField = new ParameterField(); // <-- This line is added
paramDiscreteValue = new ParameterDiscreteValue(); // <-- This line is added
paramField.Name = "name";
paramDiscreteValue.Value = BLDashboard.custname;
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
paramField = new ParameterField(); // <-- This line is added
paramDiscreteValue = new ParameterDiscreteValue(); // <-- This line is added
paramField.Name = "address";
paramDiscreteValue.Value = BLDashboard.add;
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
paramField = new ParameterField(); // <-- This line is added
paramDiscreteValue = new ParameterDiscreteValue(); // <-- This line is added
paramField.Name = "email";
paramDiscreteValue.Value = BLDashboard.email;
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
crystalReportViewer1.ParameterFieldInfo = paramFields;
我用谷歌搜索了一些人告诉setdatasource然后将vlaue传递给参数我也试过了,但它没有炒锅。
请heclp坚持这几天。
谢谢
我尝试了什么:
我在断点时尝试检查每个参数值。各种代码如
I googled and some one told to setdatasource before passing vlaue to parameter i tried that too but it didnt wok.
Please heclp been stucked on this for days.
Thanks
What I have tried:
I have tried check each parameter value while in breakpoint. And various codes like
try
{
// Export the Report to Response stream in PDF format and file name Customers
//printbanqoute.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "Customers");
printbanqoute.ExportToHttpResponse(ExportFormatType.PortableDocFormat, response, true, "Quotation");
// There are other format options available such as Word, Excel, CVS, and HTML in the ExportFormatType Enum given by crystal reports
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
ex = null;
}
但是在响应中获取错误 - 当前不存在名称响应 context
But gets error on "response" - The name 'response' does not exist in current context
推荐答案
我能够解决我的问题。我在`crystalviewer1_Load`事件中写了所有代码,即;导出和发送电子邮件以及将数据填充到水晶报告中。所以我不得不创建一个按钮电子邮件导出和发送电子邮件。
继承我的代码导出和发送电子邮件,Button1是crystalviewer上的电子邮件按钮:
I am able to solve my issue. I was writing all codes in `crystalviewer1_Load` event ie; exporting and email as well as populating data to crystal report. So I had to create a Button Email to export and email.
Heres my code to export and email, Button1 is the email button on crystalviewer:
private void button1_Click(object sender, EventArgs e)
{
try
{
billprint.ExportToDisk(ExportFormatType.PortableDocFormat, "E:\\" + filename);
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
try
{
MailMessage mm = new MailMessage();
string toemail = BLDashboard.email;
string custnm = BLDashboard.custname;
mm.From = new MailAddress("operations@kaem.in", "Kashif Ahhmed");
mm.To.Add(new MailAddress(toemail, custnm));
mm.IsBodyHtml = true;
string name = BLDashboard.custname;
mm.Subject = "Bill from Indian Restaurant";
//mm.Body = "Testing Crsytel Report Attachment send via Email";
String Body = "<div>Hello " + name + ",<br> Thank you for considersing us for your next Party/Event, here is the Bill for the Party/Event.<br> If any queries you can reach us at 6096464445. <br> Thank You</div>";
mm.Body = Body;
//mm.Attachments.Add(new Attachment(rpt.ExportToStream(ExportFormatType.PortableDocFormat), fileName));
mm.Attachments.Add(new Attachment("E:\\" + filename));
SmtpClient sc = new SmtpClient("smtp.kaem.in");
sc.Credentials = new NetworkCredential("emailadd", "*********");
sc.Send(mm);
// MailMessage msg = mm.CreateMailMessage("mr.markwhite1@gmail.com", replacements, Body, new System.Web.UI.Control());
MessageBox.Show("Email successfully sent to " + toemail);
}
catch (Exception e1)
{
MessageBox.Show("Unable to send email to mr.markwhite1@gmail.com due to following error:\n\n" + e1.Message, "Email send error", MessageBoxButtons.OK, MessageBoxIcon.Error);
//{
// this.SendEmail(emailId, subject, body, rpt, fileName);
//}
}
}
这篇关于将水晶报告导出为PDF会丢失参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!