我正在尝试将Crystal Reports连接到ODBC for MySql。 我跟着这篇文章 http://www.tek-tips.com/faqs.cfm?fid=4870
它始终以数据库登录失败结束。 这是我的代码:
private void genReportBulananMaterialPasir(string[] param)
{
ViewSummaryMaterialPasir report = new ViewSummaryMaterialPasir();
//Get SQL Server Details
string zServer = server;
string zDatabase = database;
string zUsername = uid;
string zPassword = password;
ConnectionInfo ciReportConnection = new ConnectionInfo();
ciReportConnection.ServerName = zServer;
ciReportConnection.DatabaseName = zDatabase;
ciReportConnection.UserID = "ROOT";
ciReportConnection.Password = "12345";
//Assign data source details to tables
foreach (Table table in report.Database.Tables)
{
table.LogOnInfo.ConnectionInfo = ciReportConnection;
table.ApplyLogOnInfo(table.LogOnInfo);
}
foreach (ReportDocument subrep in report.Subreports)
{
foreach (Table table in subrep.Database.Tables)
{
table.LogOnInfo.ConnectionInfo = ciReportConnection;
table.ApplyLogOnInfo(table.LogOnInfo);
}
}
//Assign data source details to the report viewer
if (this.crystalReportViewer1.LogOnInfo != null)
{
TableLogOnInfos tlInfo = this.crystalReportViewer1.LogOnInfo;
foreach (TableLogOnInfo tbloginfo in tlInfo)
{
tbloginfo.ConnectionInfo = ciReportConnection;
}
}
//String formula = "{tx_materialpasir.status} >=0 ";
//"and {tx_materialpasir.tanggal} like '%" + param[0] + "' " +
//"and {tx_materialpasir.konsumen} = " + param[1] + " " +
//"and {tx_materialpasir.plant} = " + param[2] +"";
report.SetDatabaseLogon
("ROOT", "12345");
report.DataDefinition.FormulaFields["sPeriode"].Text = "'" + periode(param[0]) + "'";
//crystalReportViewer1.SelectionFormula = formula;
crystalReportViewer1.ReportSource = report;
crystalReportViewer1.Refresh();
}