Click here to Skip to main content
11,493,391 members (69,646 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP ASP.NET Visual-Studio C#4.0 , +
i am getting this error when i try to print crystal report from button click event
this is my code

 protected void Button2_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
        SqlDataAdapter da = null;
        DataTable dt = new DataTable();
        DataTable dt1 = new DataTable();
 
        con.Open();
 

        SqlCommand cmd = new SqlCommand("SELECT * FROM Transactions WHERE idcount = @idcount ");
 
        cmd.Connection = con;
        cmd.Parameters.Add("@idcount", SqlDbType.Decimal).Value = TextBox1.Text;
 

        da = new SqlDataAdapter(cmd);
        dt.Clear();
        da.Fill(dt);
        if (dt.Rows.Count > 0)
        {
 
            ReportDocument Report = new ReportDocument();
            Report.Load(Server.MapPath("~/CrystalReport.rpt"));
            Report.SetDataSource(dt);
            TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
            TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
            ConnectionInfo crConnectionInfo = new ConnectionInfo();
            Tables CrTables;
            Report.SetDatabaseLogon("sa", "123456789", @"TRAINING-ROOM-8", "newMreport");
            CrystalReportViewer1.ReportSource = Report;
            CrystalReportViewer1.DataBind();
            CrTables = Report.Database.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
            {
                crtableLogoninfo = CrTable.LogOnInfo;
                crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                CrTable.ApplyLogOnInfo(crtableLogoninfo);
            }
 
            Report.Refresh();
            Report.PrintToPrinter(1, true, 1, 1);    <--- ERROR
            con.Close();
        }
Posted 21-Jan-13 19:41pm
Comments
lailac88 at 21-Mar-13 22:08pm
   
Here's an example how to view your Crystal report:

Dim report As New ReportDocument
report.Load("C:\somewhere\myreport.rpt")
CrystalReportViewer1.ReportSource = report
CrystalReportViewer1.Refresh()

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 408
1 F-ES Sitecore 244
2 Maciej Los 241
3 CPallini 233
4 Nakul Chaudhari 225
0 Sergey Alexandrovich Kryukov 10,237
1 OriginalGriff 8,730
2 Sascha Lefèvre 3,664
3 Maciej Los 3,392
4 Richard Deeming 2,500


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 20 Oct 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100