嗨朋友我已经创建了一个带参数的水晶报表,它在源代码中执行时成功运行,但在 IIS 之后配置时它没有加载,它显示错误,如无法连接登录参数。请检查我的代码并纠正我。
嗨朋友,如果我评论 oStream = (MemoryStream)reportdocument.ExportToStream(ExportFormatType.PortableDocFormat); 这一行和 Response.BinaryWrite(oStream.ToArray()); 此报告是在 IIS 中生成的,但我没有得到正确的 pdf 格式请帮助我,我想以 pdf 格式生成请指导我
public partial class frm_MRPrint : System.Web.UI.Page
{
SqlConnection Con = new SqlConnection(ConfigurationManager.AppSettings["conn"].ToString());
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
mr();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
MemoryStream oStream;
Response.Clear();
Response.Buffer = true;
ReportDocument reportdocument = new ReportDocument();
reportdocument.Load(Server.MapPath("MR.rpt"));
reportdocument.SetDatabaseLogon("sa", "Admin123", "vivek", "PURCHASE");
reportdocument.SetParameterValue("MRNO", ddlmrno.SelectedItem.Text);
CrystalReportViewer1.ReportSource = reportdocument;
oStream = (MemoryStream)reportdocument.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();
}
//in case you want to export it as an attachment use the line below
//crReport.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "Your Exported File Name");
}
public void mr()
{
ddlmrno.Items.Clear();
ListItem frstitem = new ListItem();
frstitem.Text = "- Select -";
ddlmrno.Items.Add(frstitem);
ddlmrno.SelectedIndex = 0;
Con.Open();
string sql = "";
sql = "select distinct(MRNO) from dbo.tbl_KKSMR where status=1 order by MRNO asc";
SqlCommand cmd = new SqlCommand(sql, Con);
SqlDataReader rdr;
try
{
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
ListItem newItem = new ListItem();
newItem.Text = rdr["MRNO"].ToString().Trim();
newItem.Value = rdr["MRNO"].ToString().Trim();
ddlmrno.Items.Add(newItem);
}
rdr.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
cmd.Dispose();
} Con.Close();
}
}