Click here to Skip to main content
14,381,948 members
Rate this:
Please Sign up or sign in to vote.
Im using VS 2010. I have a form with a textbox and reportviewer on it.

In my form textbox client inserts a value name Invoicenumber then when user press button the reportviewer must generate and in reportviewer textbox i want invoice number to display.

I created a parameter for invoicenumber: Parameter!invoicenumber and called it in my reportviewer expression. What am i missing
This is my Form code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Windows.Forms.PropertyGridInternal;

namespace WindowsFormsApplication1
    public partial class Form12 : Form
        string ConnectionString = @"Data Source=Admin-PC\SQLEXPRESS;Initial Catalog=Couriers;Integrated Security=True";
        SqlCommand com;
        // SqlDataAdapter da;
        // DataSet ds;
        String str;
        DataTable dt;

        public Form12()

        private void Form12_Load(object sender, EventArgs e)
            // TODO: This line of code loads data into the 'couriersDataSet20.Cycle' table. You can move, or remove it, as needed.
            SqlConnection sqlConn = new SqlConnection(ConnectionString);
            str = "SELECT * from Cycle";
            SqlCommand com = new SqlCommand(str, sqlConn);
            SqlDataAdapter da = new SqlDataAdapter(com);
            DataSet ds = new DataSet();
            da.Fill(ds, "Cycle");
            dt = ds.Tables["Cycle"];
            comboBox1.DataSource = ds.Tables["Cycle"];
            comboBox1.DisplayMember = "CycleNumber";
            comboBox1.Text = "select";
            textBox3.Text = 
            textBox4.Text = "";

          //  this.reportViewer1.LocalReport.ReportEmbeddedResource = "Report2.rdlc";
           // SqlParameter sp = new SqlParameter("invoicenumber", this.textBox2.Text);


        private void textBox1_TextChanged(object sender, EventArgs e)

        private void button1_Click(object sender, EventArgs e)

            // TODO: This line of code loads data into the 'DataSet1.Waybills' table. You can move, or remove it, as needed.
            this.WaybillsTableAdapter.Fill(this.DataSet1.Waybills, textBox1.Text, textBox3.Text, textBox4.Text);

            Random random = new Random();

            int num = random.Next(1, 10000);

            textBox2.Text= Convert.ToString(num);

        	    new Microsoft.Reporting.WinForms.ReportParameter("invoicenumber", textBox2.Text);


        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            SqlConnection sqlConn = new SqlConnection(@"Data Source=Admin-PC\SQLEXPRESS;Initial Catalog=Couriers;Integrated Security=True");
            str = "SELECT * from Cycle where CycleNumber='" + comboBox1.Text.Trim() + "'";
            com = new SqlCommand(str, sqlConn);
            SqlDataReader reader = com.ExecuteReader();

            if (reader.Read())
                textBox3.Text = reader["StartDate"].ToString();
                textBox4.Text = reader["EndDate"].ToString();

        private void label4_Click(object sender, EventArgs e)
            Random random = new Random();

            int num = random.Next(1, 10000);

            label4.Text = Convert.ToString(num);

As u see my textbox 2 generates a random number that i want to use as invoice number.

But now the problem is im not sure how to display textbox2 input into my reportviewer
Updated 3-Sep-12 9:44am
Oshtri Deka 3-Sep-12 7:23am
Can we see the code please?
GoggatjieLiesl 3-Sep-12 7:31am
What code you looking for, the form or report code
Rate this:
Please Sign up or sign in to vote.

Solution 1

GoggatjieLiesl 3-Sep-12 8:15am
Thanks will check it out, thanks for the quick reply
Rate this:
Please Sign up or sign in to vote.

Solution 2


First your method of generating Invoice number is incorrect. You should not use logic for generating Invoice number in C#. Instead i suggest you to use AutoIncrement Number in database to generate your invoice Number. Or if you have complex InvoiceNumber then you can create one SQL Function.

Second problem is in your connectionString location, You should not hardcode your connectionString. Use Configuration file to place your connectionString.

Now your problem will be easy, When user Save the Invoice and Press print button you can get Invoice Number form database.

And very last suggestion, Your code should be neat and clean.

Hope this helps you,
-Amit Gajjar
GoggatjieLiesl 4-Sep-12 1:32am
Thank you very much for this answer and for helping me out and helping me right. Im still a beginner and it is nice to see that there is still ppl that are patient enough to help us out. Thanks Amit
AmitGajjar 4-Sep-12 1:34am
Mark solution as answered if it answer your question.

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

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