0

WindowsForm C#のCrystal Report 2008

エラー:オブジェクト参照がオブジェクトのインスタンスに設定されていません。

それを修正する方法は?

string appConn = ConfigurationManager.ConnectionStrings["connDB"].ConnectionString;

private void button5_Click(object sender, EventArgs e)
        {
            SqlConnection objConn = new SqlConnection();
            SqlCommand objCmd = new SqlCommand();
            SqlDataAdapter dtAdapter = new SqlDataAdapter();

            DataSet ds = new DataSet();
            DataTable dt;
            string strSQL;

            strSQL = "SELECT * FROM filesTA WHERE ChkDate = '" + dateTimePicker2.Value.ToString("yyyy-MM-dd") + "'";

            objConn.ConnectionString = appConn;
            var _with1 = objCmd;
            _with1.Connection = objConn;
            _with1.CommandText = strSQL;
            _with1.CommandType = CommandType.Text;
            dtAdapter.SelectCommand = objCmd;

            dtAdapter.Fill(ds, "myDataTable");
            dt = ds.Tables[0];

            dtAdapter = null;
            objConn.Close();
            objConn = null;

            ReportDocument rpt = new ReportDocument();
                   rpt.Load(System.Web.HttpContext.Current.Server.MapPath("Report\\CrystalReport1.rpt")); <<< Error
            rpt.SetDataSource(dt);
            this.crystalReportViewer1.ReportSource = rpt;
            this.crystalReportViewer1.Refresh();
        }

お願い助けて。お時間をいただきありがとうございます。:)

4

1 に答える 1

0

さて、スタックトレースを詳しく調べることをお勧めします。しかし、私の推測では、それSystem.Web.HttpContext.Currentはnullです。多くの人は、これがnullになる可能性があることに気づいていません。そのため、そのプロパティを参照しようとするとServer、null参照例外が発生します。

于 2012-11-20T03:00:31.120 に答える