using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
namespace reporttest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
this.reportViewer1.LocalReport.ReportPath = @"D:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\reporttest\reporttest\Report1.rdlc";
ReportParameter rp = new ReportParameter("m", this.textBox1.Text);
this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp });
this.reportViewer1.RefreshReport();
}
static void Main()
{
Application.Run(new Form1());
}
}
}
一定要在Form里添加一个BUTTON按钮,因为现在的REPORTVIEW其实是静态的,其实已经将TEXTBOX的值赋值给参数m,但是TEXTBOX初始的值为空(除非你先设定textbox的值例如textBox1.text="123"),这种情况下你在TEXTBOX中输入无数次值也不会将改变的值赋值给参数,只能通过button方法,将textbox的值赋值给参数,在刷新一下,就出来了.当然前提是要求在Report1的参数中添加过m参数,并且在响应的TEXTBOX表达式中写入=Parameters!m.Value