导出datagrid详细信息到excel时出错? [英] error while exporting datagrid details to excel?

查看:103
本文介绍了导出datagrid详细信息到excel时出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将datagrid详细信息导出到excel时出现错误

这是我的btnExport代码..

hi am getting error while exporting datagrid details to excel

here is my btnExport code..

   private void btnExport_Click(object sender, EventArgs e)
        {
            lblMessage.Text = "";
            // Export all the details
            try
            {
                // Get the datatable to export			
                DataTable dtEmployee = dsEmployee.Tables["tblTicketing"].Copy();

                // Export all the details to Excel
                RKLib.ExportData.Export objExport = new RKLib.ExportData.Export("Win");
                objExport.ExportDetails(dtEmployee, Export.ExportFormat.Excel, "C:\\Ticketing.xls");
                lblMessage.Text = "Successfully exported to C:\\Ticketing.xls";
            }
            catch (Exception Ex)
            {
                lblMessage.Text = Ex.Message;
            }

        }
error is like object reference is not set to an instance...


有人可以建议我吗?
谢谢u


can any one suggest me?
thank u

推荐答案

这意味着未实例化其中一个变量,并且抛出NullReferenceException.
在调试"模式下运行代码,您可以找到哪个变量引发了异常.
This means that one of the variable is not instantiated and it is throwing NullReferenceException.
Run the code in Debug mode and you can find which variable is throwing the exception.


您的代码在语法上是正确的

Your code is syntactically right

DataTable dtEmployee = dsEmployee.Tables["tblTicketing"].Copy(); 



确保"dsEmployee"包含名为"tblTicketing"的数据表



make sure that "dsEmployee" contains a datatable named "tblTicketing"


这篇关于导出datagrid详细信息到excel时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆