日期:2014-05-17  浏览次数:20635 次

如何在同一表单中的不同事件中共用一个dataset?
、在表单入口处定义了
  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();