表单文本框值传递给Reportviewer中的文本框

表单文本框值传递给Reportviewer中的文本框

本文介绍了如何将C#表单文本框值传递给Reportviewer中的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VS2010.我有一个带有文本框和reportviewer的表单.

在我的表单文本框中,客户端插入一个值名称Invoicenumber,然后当用户按下按钮时,reportviewer必须生成,并且在reportviewer文本框中,我希望显示发票编号.

我为发票编号创建了一个参数:Parameter!invoicenumber,并在我的reportviewer表达式中对其进行了调用.我想念什么
这是我的表格代码

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()
        {
            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);
        }
    }
}


如您所见,我的文本框2生成一个我要用作发票号的随机数.

但是,现在的问题是我不确定如何在我的reportviewer中显示textbox2输入.


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

推荐答案



这篇关于如何将C#表单文本框值传递给Reportviewer中的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 22:57