当我点击第二页时...对话框打开并再次询问登录信息
这是我点击第二页时出现的错误 http://i.imgur.com/8y70goi.png
这是我的代码
public void LoadReport()
{
crReportDocument = new ReportDocument();
connectionInfo = new ConnectionInfo();
ParameterField paramField1 = new ParameterField();
ParameterFields paramFields = new ParameterFields();
ParameterDiscreteValue paramDiscreteValue1 = new ParameterDiscreteValue();
//p1
paramField1.Name = "id";
paramDiscreteValue1.Value = Request.QueryString["Id"].ToString();
paramField1.CurrentValues.Add(paramDiscreteValue1);
paramFields.Add(paramField1);
CrystalReportViewer1.ReportSource = crReportDocument;
crReportDocument.Load(Server.MapPath("~/CrystalReport.rpt"));
connectionInfo.ServerName = ConfigurationManager.AppSettings["ServerName"];
connectionInfo.DatabaseName = ConfigurationManager.AppSettings["DataBaseName"];
connectionInfo.UserID = ConfigurationManager.AppSettings["DataBaseUserID"];
connectionInfo.Password = ConfigurationManager.AppSettings["DataBasePasswordName"];
SetDBLogonForReport(connectionInfo);
CrystalReportViewer1.ParameterFieldInfo = paramFields;
CrystalReportViewer1.EnableDatabaseLogonPrompt = false;
CrystalReportViewer1.EnableParameterPrompt = false;
CrystalReportViewer1.Visible = true;
DataSet dsTemp = new DataSet();
DBAccess dbAccess = new DBAccess();
SqlParameter spId = new SqlParameter("@Id", Request.QueryString["Id"].ToString());
SqlParameter[] sqlParams = new SqlParameter[] { spId };
dsTemp = dbAccess.ExecuteDataset("sp_GetInvestigationData", sqlParams);
crReportDocument.SetDataSource(dsTemp.Tables[0]);
CrystalReportViewer1.ReportSource = crReportDocument;
CrystalReportSource1.ReportDocument.SetParameterValue(0, Request.QueryString["Id"].ToString());
}
private void SetDBLogonForReport(ConnectionInfo connectionInfo)
{
TableLogOnInfos tableLogOnInfos = CrystalReportViewer1.LogOnInfo;
foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)
{
tableLogOnInfo.ConnectionInfo = connectionInfo;
}
}
由于
答案 0 :(得分:0)
确保所有地方都有相同版本的水晶报告。看看是否安装了required packages试试这个
private ConnectionInfo crConnectionInfo = new ConnectionInfo();
ReportDocument rpt = new ReportDocument();
protected void Page_Load(object sender, EventArgs e)
{
BindReport();
}
private void BindReport()
{
rpt.Load(Server.MapPath("report1.rpt"));
DataSet ds = getReportData();
rpt.SetDataSource(ds.Tables[0]);
CrystalReportViewer1.ReportSource = rpt;
}
private DataSet getReportData()
{
DataSet ds = new DataSet();
string ConnectionString = ConfigurationManager.ConnectionStrings["myconn"].ConnectionString;
SqlConnection con = new SqlConnection(ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "GetProductList";
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
cmd.Connection = con;
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(ds, "ctable");
con.Close();
return ds;
}
您可能会看到另一个示例here