我有一个如下所示的代码:
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);
}
在这一行
ds = OclsCommonVariables.SetDataInDataSetFromEnumerableList(ref ds, reportData.AsEnumerable());
程序抛出异常而不进入函数内部
抛出的异常是“对象引用未设置为对象实例”。
该函数需要三个参数
public DataSet SetDataInDataSetFromEnumerableList(ref DataSet DS, object obj, params string[] FieldNames)
{
return ds;
}