我用參數創建了一個水晶報表,但它沒有加載這個值。它只是顯示標題,我只是指列名。請檢查我的代碼並糾正我。我試圖將報告加載到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();
}
你爲什麼寫:reportdocument.SetDatabaseLogon(「」,「」,「Aravind」,「MySampleDB」);?你有沒有嘗試過:cryReportDocument.SetDatabaseLogon(「UserName」,「Password」,「DatabaseServerName」,「」); ? – 2012-07-12 08:56:40