、在表单入口处定义了
public DataSet myds2 = new DataSet ();
2、在“查询”控件里生成了myds2(这是第一个按钮的事件)
DataSet myds2 = mybase.getds("select * from sb where sbbh='" + this.textBox7.Text.Trim() + "'and nf='" + this.numericUpDown4.Value.ToString().Trim() + "'and yf='" + this.numericUpDown3.Value.ToString().Trim() + "'", "table1");
if (myds2.Tables[0].Rows.Count != 0)
{}
3、想在“打印”控件中直接将上一步生成的myds2做为水晶报表的数据源来进行打印(这是第二个按钮的事件)
private void button4_Click_1(object sender, EventArgs e)
{
ReportDocument rptDoc = new ReportDocument();
string rptPath = "";
string serverPath = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\"));
rptPath = serverPath + @"\zlsfp.rpt";
rptDoc.Load(rptPath);
rptDoc.SetDataSource(myds2.Tables [0]); //在这儿直接应用刚才第二步生成的myds2
rptDoc.Refresh();
this.crystalReportViewer1.ReportSource = rptDoc;
}运行时报错:无法找到表 0。
请问怎么解决。谢谢
public DataSet myds2 = new DataSet ();
2、在“查询”控件里生成了myds2(这是第一个按钮的事件)
DataSet myds2 = mybase.getds("select * from sb where sbbh='" + this.textBox7.Text.Trim() + "'and nf='" + this.numericUpDown4.Value.ToString().Trim() + "'and yf='" + this.numericUpDown3.Value.ToString().Trim() + "'", "table1");
if (myds2.Tables[0].Rows.Count != 0)
{}
3、想在“打印”控件中直接将上一步生成的myds2做为水晶报表的数据源来进行打印(这是第二个按钮的事件)
private void button4_Click_1(object sender, EventArgs e)
{
ReportDocument rptDoc = new ReportDocument();
string rptPath = "";
string serverPath = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\"));
rptPath = serverPath + @"\zlsfp.rpt";
rptDoc.Load(rptPath);
rptDoc.SetDataSource(myds2.Tables [0]); //在这儿直接应用刚才第二步生成的myds2
rptDoc.Refresh();
this.crystalReportViewer1.ReportSource = rptDoc;
}运行时报错:无法找到表 0。
请问怎么解决。谢谢
解决方案 »
- 问个C#多线程问题~
- C#中如何利用正则表达式搜索这个字符串?
- 怎么实现监视流媒体功能,如迅雷的监视流媒体功能.
- listview控件 如何让显示的图片在上面,文字在下面
- 我刚学treeview控件,不知怎么用呢,谢谢大家帮我一下
- 数据绑定控件问题
- 关于一个有难度的拷屏操作,一个panel控件固定其大小,其中放置picturebox控件,背景图片很大,panel无法全部显示,但是我想把整个图片用
- 问下datatable里的数据处理
- 我的程序连接错误,大家帮忙看看好吗,谢谢!
- [winform]生成无限级别的treeview ,100分
- metro中怎么取到一个文件下的所有文件
- Java和C#UDP通信问题
我觉得我应该为这个社区做点贡献了,就从你开始吧两个事件为什么不能共用一个数据的原因是,每次请求都会生成一个新的对象实例(新的会话),只有静态数据或Session,Cookie之类才能被重新使用(实际上都是直接或间接的通过客户端cookie的方式来实现的)
现在来说怎么解决你的问题
很简单,把你获取这个DataSet的这个函数提取出来另作一个函数
两个事件需要用这个数据时直接调用即可
当然你也可以再第一次获取这个DataSet后把数据存储到静态DataSet中
在后面的请求中就能用了,明白?