C# 向RDLC报表传入参数出错 急求解答!!
form里是个reportViewer和一个textbox,要把textbox.text的值传给报表里的textbox上,老是出错。代码在如下usingSystem;us...
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;
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();
}
}
}
报表参数也定义了,就是不对,为什么? 展开
1个回答
展开全部
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
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
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询