C# 向RDLC报表传入参数出错 急求解答!!
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C# 向RDLC报表传入参数出错 急求解答!!相关的知识,希望对你有一定的参考价值。
form里是个reportViewer和一个textbox,要把textbox.text的值传给报表里的textbox上,老是出错。代码在如下
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)
this.reportViewer1.LocalReport.ReportEmbeddedResource = @"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.LocalReport.SetParameters(new ReportParameter[] rp );
this.reportViewer1.RefreshReport();
报表参数也定义了,就是不对,为什么?
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本回答被提问者和网友采纳
以上是关于C# 向RDLC报表传入参数出错 急求解答!!的主要内容,如果未能解决你的问题,请参考以下文章
vs 2015 rdlc报表绑定datagridview中的数据
C# RDLC报表如何调整textbox内多行文字的行间距?