Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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
C#
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
Comments
anglo0072 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900