Crystal Report を使用してストアド プロシージャからデータを取得していますが、これをページ オンロード関数で使用すると適切な方法で動作しますが、静的関数では動作しません。最後の行に「オブジェクト参照がオブジェクトのインスタンスに設定されていません」というエラーが表示されます。 .
public static void DrawGrids()
{
ReportDocument rptDoc = new ReportDocument();
ComplaintTrackingSystem.Reports.Datas dss = new Reports.Datas();
DataTable dt = new DataTable();
DataSet ds;
Hashtable ObjParameters = new Hashtable();
BusinessLogicLayer ObjBusiness = new BusinessLogicLayer();
ds =ObjBusiness.SPDataSet(ObjParameters,"SelectUserComplaintsByComptIdReport");
dt.TableName = "Crystal Report Example";
dt = ds.Tables[0]; //This function is located below this function
dss.Tables[0].Merge(dt);
rptDoc.Load(HttpContext.Current.Server.MapPath("../Reports/ComplaintReport.rpt"));
//set dataset to the report viewer.
rptDoc.SetDataSource(dss);
CrystalDecisions.Web.CrystalReportViewer obj = new CrystalDecisions.Web.CrystalReportViewer();
Page p = HttpContext.Current.Handler as Page;
obj = (CrystalDecisions.Web.CrystalReportViewer)p.FindControl("CrystalReportViewer1");
obj.ReportSource = rptDoc;
}