读者朋友:
您好,SQL数据库有密码的话,就会弹出那个对话框,你可以使用代码动态为水晶报表设置一下数据源,套用下面这段代码试一下。
//绑定报表数据
private void BindCrystalReports()
{
string path1 = Server.MapPath("~\\Report\\");
string path2 = path1 + "repOrder.rpt";
ReportDocument repDoc = new ReportDocument();
repDoc.Load(path2);
SetDBLogonForReport(repDoc); //设置数据登录信息
crOrder.ReportSource = repDoc;
string selectionFormula = "{htOrder.htID} =" + txtHtID.Text.Trim();//设置报表数据筛选公式
repDoc.DataDefinition.RecordSelectionFormula = selectFormula;
crOrder. DataBind ();
}
//设置登录信息
private void SetDBLogonForReport(ReportDocument reportDocument)
{
try
{
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = ConfigurationManager.AppSettings["ServerName"];
connectionInfo.DatabaseName = ConfigurationManager.AppSettings["DatabaseName"];
connectionInfo.UserID = ConfigurationManager.AppSettings["UserID"];
connectionInfo.Password = ConfigurationManager.AppSettings["Password"];
Tables tables = reportDocument.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogonInfo);
}
}
catch
{
lblNote.Text = "<script>alert('数据库登录信息不正确!');</script>";
}
}