日期:2014-05-18  浏览次数:20950 次

导出dataGridView 的数据到EXCEL 中

  private void button2_Click(object sender, EventArgs e)
  {
  Productdiscount pd = new Productdiscount();
  Serviceinformation si = new Serviceinformation();
  if (MessageBox.Show("您确定要导出吗?", "提示",
  MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  {
  ExportDate ep = new ExportDate();
  ep.dgvOutPutExcel(dataGridView1);这个有值
  ep.dgvOutPutExcel(pd.dataGridView1);我断点看了这个没有值
  ep.dgvOutPutExcel(si.dataGridView1);我断点看了这个没有值
这是为什么。知道的代码简略打下


  }

------解决方案--------------------
Productdiscount pd = new Productdiscount();
Serviceinformation si = new Serviceinformation();

你这里new了两个新的对象,新对象里面的dataGridView和已经有数据的dataGridView不是一个
------解决方案--------------------
探讨
不是一个的,Productdiscount();有一个
Serviceinformation();也有一个。都不是一养的