Click here to Skip to main content
15,884,628 members

how to pass C# form textbox value to textbox in Reportviewer

GoggatjieLiesl asked:

Open original thread
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
C#
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()
        {
            InitializeComponent();
        }

        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.
            this.cycleTableAdapter.Fill(this.couriersDataSet20.Cycle);
            SqlConnection sqlConn = new SqlConnection(ConnectionString);
            sqlConn.Open();
            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"];
            sqlConn.Close();
            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);
            //this.reportViewer1.RefreshReport();


            
        }

        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);
                                     
          

            this.reportViewer1.RefreshReport();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            SqlConnection sqlConn = new SqlConnection(@"Data Source=Admin-PC\SQLEXPRESS;Initial Catalog=Couriers;Integrated Security=True");
            sqlConn.Open();
            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();
            }
            sqlConn.Close();
            reader.Close();
        }

        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
Tags: C#, Parameter, Reporting

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

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 http://www.codeproject.com/info/cpol10.aspx.



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