Click here to Skip to main content
14,544,424 members

How to print crystal report on different paper size

Member 14649908 asked:

Open original thread
I have a combobox whose item is as below:
40 Barcodes per sheet (A4) (1.799" X 1.003")
30 Barcodes per sheet (2.625" X 1")
24 Barcodes per sheet (A4) (2.48" X 1.334")
20 Barcodes per sheet (4" X 1")
18 Barcodes per sheet (A4) (2.5" X 1.835")
14 Barcodes per sheet (A4) (4" X 1.33")
12 Barcodes per sheet (A4) (2.5" X 2.834")
10 Barcodes per sheet (A4) (4" X 2")

I want to print the crystal report depending upon the item selected from combobox.How to do that ?

What I have tried:

public void generateBarcode()
        {
            try
            {
                string cs =ConfigurationManager.ConnectionStrings["abc"].ConnectionString;
                SqlConnection con = new SqlConnection(cs);
                string query = "SELECT * FROM products WHERE id='" + txtProductId.Text + "'";
                for (int i = 1; i < int.Parse(txtNoOfCopies.Text); i++)
                {
                    query += "UNION ALL SELECT * FROM products WHERE id= '" + int.Parse(txtProductId.Text) + "'";
                }
                SqlDataAdapter sda = new SqlDataAdapter(query, con);
                DataSet ds = new DataSet();
                sda.Fill(ds, "products");
                crystal.SetDataSource(ds);
                crystalReportViewer1.ReportSource = crystal;
            }
            catch (SqlException sqlEx)
            {
                MessageBox.Show(sqlEx.Message.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnGenerateBarcode_Click(object sender, EventArgs e)
        {
           generateBarcode()
        }
Tags: .NET, CrystalReports, barcode, WindowsForms

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).




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