我用参数创建了一个水晶报表,但它没有加载该值。它只显示标题,我只是列名。请检查我的代码并纠正我。我试图将报告加载到pdf格式,显示“加载报告失败”之类的错误。请纠正我。
protected void Button2_Click(object sender, EventArgs e)
{
ReportDocument reportdocument = new ReportDocument();
reportdocument.Load(Server.MapPath("CrystalReport.rpt"));
reportdocument.SetDatabaseLogon("", "", "Aravind", "MySampleDB");
reportdocument.SetParameterValue("MRNO", TextBox1.Text);
CrystalReportViewer1.ReportSource = reportdocument;
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
EXPORTREPORT();
}
private void EXPORTREPORT()
{
MemoryStream oStream;
Response.Clear();
Response.Buffer = true;
ReportDocument reportdocument = new ReportDocument();
reportdocument.Load(Server.MapPath("CrystalReort.rpt"));
reportdocument.SetDatabaseLogon("", "", "Aravind", "MySampleDB");
reportdocument.SetParameterValue("MRNO",TextBox1.Text);
CrystalReportViewer1.ReportSource = reportdocument;
oStream = (MemoryStream)reportdocument.ExportToStream(ExportFormatType.PortableDocFormat);
//oStream = (MemoryStream)crReport.ExportToStream(ExportFormatType.PortableDocFormat);
Response.ContentType = "application/pdf";
try
{
//write report to the Response stream
Response.BinaryWrite(oStream.ToArray());
Response.End();
}
catch (Exception ex)
{
Label2.Visible = true;
Label2.Text = "ERROR:" + Server.HtmlEncode(ex.Message.ToString());
}
finally
{
//clear stream
oStream.Flush();
oStream.Close();
oStream.Dispose();
}
答案 0 :(得分:0)
您确定报告的名称是CrystalReort.rpt
吗?而不是更常见的名称CrystalReport.rpt
。
它是否也位于您网站的根目录中?
答案 1 :(得分:0)
将值转换为所需类型,如果其编号为Convert.ToDouble(TextBox1.Text)
答案 2 :(得分:0)
什么类型的MRNO? 也可以尝试下面的代码,这可能对你有帮助。 rptDoc.ExportOptions.ExportDestinationType = ExportDestinationType.NoDestination;
Stream getStreams = rptDoc.ExportToStream(ExportFormatType.PortableDocFormat);
byte[] getbytes = GetStreamAsByteArray(getStreams);
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Length", getbytes.Length.ToString());
Response.BinaryWrite(getbytes);
答案 3 :(得分:0)
将以下代码写入页面的加载事件中。
if (crystalReportDoc != null)
{
crystalReportDoc.Close();
crystalReportDoc.Dispose();
GC.Collect();
}