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。
请问怎么解决。谢谢
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。
请问怎么解决。谢谢
2、在调用该变量前绑定数据源(Web里注意IsPostback属性的使用);
我已经设为共用的全局变量了,而且是在同一表单中调用,
我做的是winform的
而且我一般是用SqlDataAdapter做一个Fill(DataSet,"表名");如果报错为“未将对象引用设置到对象的实例”,一般来说是不是你运行到这一句的时候,是不是已经将对象实例释放掉了?或者指向不正确?
谢谢大家