我有多个服务器和数据库(不同的名称),但是所有数据库的表名称都相同。我想在运行时将数据库登录信息传递给水晶报表。
我试图在运行时为Crystal报表提供服务器名称和数据库名称。用户将在登录前选择所需的服务器。但是水晶报表似乎无法识别该代码提供的服务器名称和数据库名称。 而且我还尝试了一些我在Google上找到的代码,这似乎与我想要的代码非常接近,但是有1行出现了错误,我无法弄清。
private Database crDatabase;
private Tables crTables;
private CrystalDecisions.CrystalReports.Engine.Table crTable;
private TableLogOnInfo crTableLogOnInfo;
private ConnectionInfo crConnectionInfo = new ConnectionInfo();
private CrystalReport1 crReportDocument = new CrystalReport1();
public void setLogonInfo()
{
crConnectionInfo.ServerName = "'" + lblServer.Text.Trim() + "'";
crConnectionInfo.DatabaseName = "'" + lblDatabase.Text.Trim() + "'";
crConnectionInfo.UserID = "user";
crConnectionInfo.Password = "user123";
crDatabase = crReportDocument.Database;
crTables = reportdocument.Database.Tables;
for (int i = 0; i < crTables.Count; i++)
{
crTable = **crTables**;
crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo =
crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogOnInfo);
crTable.Location = crConnectionInfo.DatabaseName + ".dbo." + crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1);
}
CrystalReportViewer.ReportSource = crReportDocument;
}
函数内部,crTable = crTables;出现错误消息。 “无法将类型'CrystalDecisions.CrystalReports.Engine.Tables'隐式转换为'CrystalDecisions.CrystalReports.Engine.Table'”