Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Visual-Studio C#4.0 , +
i want to print report based on ID by entering in Text Box when i try to print from client system its printing on server but not on client printer
 
I am using this code
   
protected void Button3_Click(object sender, EventArgs e)
    {
//SqlCommand cmd = null;
        SqlDataAdapter da = null;
        DataTable dt = new DataTable();
        DataTable dt1 = new DataTable();
 
       con.Open();
 
       
        SqlCommand cmd = new SqlCommand("SELECT * FROM Transactions WHERE report_type = @report_type ");
 
        cmd.Connection = con;
        cmd.Parameters.Add("@report_type", SqlDbType.NVarChar).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("~/Report.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.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);
            con.Close();
        }
    }
Posted 1-Dec-12 2:40am
Comments
anglo0072 at 2-Dec-12 9:13am
   
it happens when the datasource provided returns null at the time of printing.
You need to make sure that the datasource provided has continuous data feed to viewer. You can repopulate the report data just before print.
and i hope you have set autopostback true of you textbox

1 solution

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

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 105
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 31 Oct 2013
Copyright © CodeProject, 1999-2014
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