Hi,
This is the code you have to add, you need to change the report LogonInfo
, as well as the logonInfo of the tables of the report.
// This is the form
frmReports frm = new frmReports();
// Logon info
TableLogOnInfos crTableLogonInfos = new TableLogOnInfos();
//Create the report
ReportDocument reportDocument1 = new Reports.MyReport();
//Get the data from the DB
// Change this to put the connection string elements
ConnectionInfo crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerName =
System.Configuration.ConfigurationSettings.AppSettings["Server"];
crConnectionInfo.DatabaseName =
System.Configuration.ConfigurationSettings.AppSettings["DataBase"] ;
crConnectionInfo.UserID =
System.Configuration.ConfigurationSettings.AppSettings["User"] ;
crConnectionInfo.Password =
System.Configuration.ConfigurationSettings.AppSettings["Password"] ;
//Update the info in the tables of the report
foreach (CrystalDecisions.CrystalReports.Engine.Table table in
reportDocument1.Database.Tables)
{
TableLogOnInfo crTableLogonInfo = new TableLogOnInfo();
crTableLogonInfo.TableName = table.Name;
crTableLogonInfo.ConnectionInfo = crConnectionInfo;
crTableLogonInfos.Add( crTableLogonInfo);
table.ApplyLogOnInfo( crTableLogonInfo);
}
//
frm.CrystalReportsViewer.LogOnInfo = crTableLogonInfos;
frm.CrystalReportsViewer.ReportSource = reportDocument1;
frm.ShowDialog()
cheers,
Alberto said:
Sorry but I don't understand your code. What I'm doing actually to see
the preview of a report is this:
frmReports frm = new frmReports();
frm.CrystalReportsViewer.ReportSource = new Reports.MyReport();
frm.ShowDialog();
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
escribió en el mensaje Hi,
You have to setup the correct info, the below code works fine with a
SQL DB:
TableLogOnInfos crTableLogonInfos = new TableLogOnInfos();
reportDocument1 = new OpenRecords();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerName =
System.Configuration.ConfigurationSettings.AppSettings["Server"];
crConnectionInfo.DatabaseName =
System.Configuration.ConfigurationSettings.AppSettings["DataBase"] ;
crConnectionInfo.UserID =
System.Configuration.ConfigurationSettings.AppSettings["User"] ;
crConnectionInfo.Password =
System.Configuration.ConfigurationSettings.AppSettings["Password"] ;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in
reportDocument1.Database.Tables)
{
TableLogOnInfo crTableLogonInfo = new TableLogOnInfo();
crTableLogonInfo.TableName = table.Name;
crTableLogonInfo.ConnectionInfo = crConnectionInfo;
crTableLogonInfos.Add( crTableLogonInfo);
table.ApplyLogOnInfo( crTableLogonInfo);
}
CrystalReportViewer1.LogOnInfo = crTableLogonInfos;
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
My application uses Access and I have some reports. The problem is
that when I design the reports, I use the path of the database in my
machine but in the customer it will not be the same. How can I solve
this?
Thank you very much