| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 914 人关注过本帖
标题:如何在同一表单中的不同事件中共用一个dataset?
只看楼主 加入收藏
ld999
Rank: 1
等 级:新手上路
帖 子:147
专家分:0
注 册:2007-4-11
收藏
 问题点数:0 回复次数:1 
如何在同一表单中的不同事件中共用一个dataset?
1、在表单入口处定义了
  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。
请问怎么解决。谢谢
搜索更多相关主题的帖子: 表单 dataset DataSet Trim 
2008-02-08 20:49
ld999
Rank: 1
等 级:新手上路
帖 子:147
专家分:0
注 册:2007-4-11
收藏
得分:0 
请教了,各位
2008-02-09 08:25
快速回复:如何在同一表单中的不同事件中共用一个dataset?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017481 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved