0

I tried it with and without the database authentication code below.

With the authentication it fails to log in...we normally use ODBC, but I don't see how to link it to an ODBC connection.

Without the authentication, it prints me an empty report (the real report, just as if no records were returned).

Also, how do I say print whole report if I don't know how many pages it is, since it requires a from and to page parameter in the print function.

Reports were created in Crystal Reports XI v11.5

Thanks in advance for any help.

Here's what I have so far:

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);
    }
}
IronicMuffin
  • 4,182
  • 12
  • 47
  • 90

1 Answers1

1

For the connection to ODBC you should be able to use the ServerName property of your ConnectionInfo object to specify your connectionstring/dsn. Please see the following questions answers for a few examples.

How do I change a Crystal Report's ODBC database connection at runtime?

For the second part of you question, you should be able to use 0 for both page number parameters of the PrintToPrinter method to print all pages.

Hope this helps.

Community
  • 1
  • 1
Dusty
  • 4,667
  • 3
  • 29
  • 35