我尝试了使用和不使用下面的数据库身份验证代码。
通过身份验证无法登录...我们通常使用 ODBC,但我看不到如何将其链接到 ODBC 连接。
如果没有身份验证,它会打印一个空报告(真实报告,就像没有返回记录一样)。
另外,如果我不知道它有多少页,我该怎么说打印整个报告,因为它需要打印函数中的 from 和 to page 参数。
报表是在 Crystal Reports XI v11.5 中创建的
提前感谢您的帮助。
这是我到目前为止所拥有的:
printReport()
{
ReportDocument cryRpt = new ReportDocument();
cryRpt.RefreshReport += reportLoaded;
cryRpt.Load(myReport);
TableLogOnInfo crTableLogonInfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables crTables;
crConnectionInfo.ServerName = "myServer";
crConnectionInfo.DatabaseName = "myDatabase";
crConnectionInfo.UserID = "myUser";
crConnectionInfo.Password = "myPass";
crTables = cryRpt.Database.Tables;
foreach (Table table in crTables)
{
crTableLogonInfo = table.LogOnInfo;
crTableLogonInfo.ConnectionInfo = crConnectionInfo;
table.ApplyLogOnInfo(crTableLogonInfo);
}
cryRpt.SetParameterValue("@report_type", type);
cryRpt.Refresh();
}
reportLoaded(object sender, EventArgs e)
{
PrintDialog print = new PrintDialog();
DialogResult dr = print.ShowDialog();
if (dr == DialogResult.OK)
{
ReportDocument cryRpt = (ReportDocument)sender;
cryRpt.PrintOptions.PrinterName = print.PrinterSettings.PrinterName;
cryRpt.PrintToPrinter(print.PrinterSettings.Copies, print.PrinterSettings.Collate, print.PrinterSettings.FromPage, print.PrinterSettings.ToPage);
}
}