0

I have a code as shown below:

try
            {

                strReportName = Application.StartupPath + "\\Report\\Accounts\\AccTrialBalanceCrystalReport.rpt";
                DataSet ds = new System.Data.DataSet();
                SchoolSoulLibrary.clsCommonVariables OClsCommonVariables = new SchoolSoulLibrary.clsCommonVariables();
                ds = OclsCommonVariables.SetDataInDataSetFromEnumerableList(ref ds, reportData.AsEnumerable()); // Throws exception at this line.
                string[,] AryParameter = new string[,]
                    {
                        {"totalOpeningDr", vOpDr.ToString()},
                        {"totalOpeningCr", vOpCr.ToString()},    
                        {"totalCurrentDr", vCurDr.ToString()},
                        {"totalCurrentCr", vClsngDr.ToString()},  
                        {"totalClosingDr", vCurCr.ToString()},
                        {"totalClosingCr", vClsngCr.ToString()},  
                        {"schoolName", clsSchoolSoulObjects.OAcdSchoolInfo.SchoolName},
                        {"@pStartDate", startDate.ToString()},  
                        {"@pEndDate", endDate.ToString()},
                        {"@pSchoolId", schId.ToString()},  
                    };
                SchoolSoulLibrary.clsCrystalReport.SetReportSourceUsingReportPath(strReportName, ds, ref crystalReportViewer1, AryParameter);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

At this line

ds = OclsCommonVariables.SetDataInDataSetFromEnumerableList(ref ds, reportData.AsEnumerable()); 

the program throws exception without goin inside the function

Exception thrown is "Object reference not set to an instance of object".

The function takes three arguements

public DataSet SetDataInDataSetFromEnumerableList(ref DataSet DS, object obj, params string[] FieldNames)
        {
             return ds;
        }
Murtaza Munshi
  • 1,025
  • 3
  • 13
  • 37
  • Have you checked if `reportData` is null? – Charlotte Skardon Oct 09 '13 at 06:24
  • Why do you have code if you don't call it? How do you know _for sure_ that it's not called? Have you set a breakpoint at the offending line? – knittl Oct 09 '13 at 06:24
  • Could you please show where the error is thrown? ...maybe post that code as well and indicate which line it is? – Kerieks Oct 09 '13 at 06:25
  • 1
    Almost all cases of `NullReferenceException` are the same. Please see "[What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)" for some hints. – John Saunders Oct 09 '13 at 06:25
  • @ Chris Skardon: Yeaaa i checked report data is not null. @ knittl : i set the breakpoitn at the line and i am calling the function see the code again. @ user2042152 : It throws an exception at this line ds = OclsCommonVariables.SetDataInDataSetFromEnumerableList(ref ds, reportData.AsEnumerable()); – Murtaza Munshi Oct 09 '13 at 06:27
  • @ John Saunders: Thanxxx for the link it solved my problem. Apparently the problem was i declared OclsCommonVariables locally and globally so it was using the global uninitialized one. – Murtaza Munshi Oct 09 '13 at 06:35

2 Answers2

0

you need to check reportData. It would be null that is why it is throwing exception. Or it could be SetDataInDataSetFromEnumerableList method. Debug into this method and see what exactly is null.

Ehsan
  • 28,801
  • 6
  • 51
  • 61
0

Use exception's stack trace, Luc

MelnikovI
  • 886
  • 1
  • 7
  • 23