Click here to Skip to main content
15,887,322 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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...

can any one suggest me?
thank u
Posted
Updated 10-Jul-12 4:37am
v2
Comments
Shemeer NS 10-Jul-12 11:08am    
in which line you are getting error?
ythisbug 10-Jul-12 11:21am    
DataTable dtEmployee = dsEmployee.Tables["tblTicketing"].Copy();

this line am getting error

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.
 
Share this answer
 
Comments
ythisbug 10-Jul-12 11:21am    
DataTable dtEmployee = dsEmployee.Tables["tblTicketing"].Copy();

in this line am getting error..
is dat code is correct?
Kiran Susarla 10-Jul-12 12:13pm    
This means dsEmployee is null or dsEmployee does not contain a table tblTicketing.
If dsEmployee is null, create an instance of dataset and populate the dataset. There a bunch of samples available on how to populate the dataset.
Your code is syntactically right

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


make sure that "dsEmployee" contains a datatable named "tblTicketing"
 
Share this answer
 
Comments
ythisbug 10-Jul-12 11:42am    
thanks .not der can u suggest me.acually am using datagrid..
Shemeer NS 10-Jul-12 11:46am    
if you are using datagrid or gridview this is same for all.. the actual probelm is dsEmployee is null or thetre is no table tblTicketing in dsEmployee... try debugging your code to see the actual values of dataset
ythisbug 10-Jul-12 12:01pm    
ya dsEmployee is null..better solution for this?
Kiran Susarla 10-Jul-12 12:14pm    
I missed this comment. You can create an instance of dataset and populate the dsEmployee with the required data.
ythisbug 10-Jul-12 13:29pm    
ok thank u kiran

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900