protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
}
else
{
if (Session["ReportMaster"] != null)
{
ReportDocument cryRpt = (ReportDocument)Session["ReportMaster"];
CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
CrystalReportViewer1.ReportSource = cryRpt;
CrystalReportViewer1.RefreshReport();
}
}
}
catch (Exception)
{
}
}
protected void btnUser_Click(object sender, EventArgs e)
{
ParameterField paramField1 = new ParameterField();
ParameterDiscreteValue paramDiscreteValue1 = new ParameterDiscreteValue();
paramField1.Name = "@id_Document";
string Document = TextBox1.Text;
paramDiscreteValue1.Value = Document;
paramField1.CurrentValues.Add(paramDiscreteValue1);
paramFields.Add(paramField1);
ReportDocument cryRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
string filePath = System.Configuration.ConfigurationSettings.AppSettings["CrysReportDir"];
cryRpt.Load(Server.MapPath("yourReport.rpt"));
crConnectionInfo.ServerName = System.Configuration.ConfigurationSettings.AppSettings["CrysServer"];
crConnectionInfo.DatabaseName = System.Configuration.ConfigurationSettings.AppSettings["CrysDatabase"];
crConnectionInfo.UserID = System.Configuration.ConfigurationSettings.AppSettings["CrysUser"];
crConnectionInfo.Password = System.Configuration.ConfigurationSettings.AppSettings["CrysPass"];
CrTables = cryRpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
CrystalReportViewer1.ReportSource = cryRpt;
CrystalReportViewer1.ParameterFieldInfo = paramFields;
CrystalReportProperty();
Session.Add("ReportMaster", cryRpt);
}
private void CrystalReportProperty()
{
try
{
CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
CrystalReportViewer1.RefreshReport();
CrystalReportViewer1.HasRefreshButton = true;
CrystalReportViewer1.HasGotoPageButton = true;
CrystalReportViewer1.HasViewList = false;
CrystalReportViewer1.HasCrystalLogo = false;
CrystalReportViewer1.HasPageNavigationButtons = true;
CrystalReportViewer1.HasDrillUpButton = true;
CrystalReportViewer1.EnableDatabaseLogonPrompt = false;
CrystalReportViewer1.EnableParameterPrompt = false;
}
catch (Exception)
{}
}
Добавьте это в файл web.config
<appSettings>
<add key="ProviderType" value="" />
<add key="CrystalImageCleaner-AutoStart" value="true" />
<add key="CrystalImageCleaner-Sleep" value="60000" />
<add key="CrystalImageCleaner-Age" value="120000" />
<add key="CrysServer" value="servername" />
<add key="CrysDatabase" value="dbname" />
<add key="CrysUser" value="username" />
<add key="CrysPass" value="password" />
<add key="CrysReportDir" value="/" />
Надеюсь, это решит вашу проблему.