我用参数创建了一个水晶报表,但它没有加载值。它只显示标题,我的意思是只显示列名。请检查我的代码并纠正我。我曾尝试将报告加载为 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();
}