我的代碼是用於工作簿的創建者。表讀錯誤:「對象引用未設置爲對象的實例。」
該方法從DB獲取問題並將它們放入列表中。
我試圖把數據放到我的問題列表中,我有一個問題類和getpageDB方法,但仍然得到錯誤「對象引用不設置到對象的實例。」
public DataSet getPageDB(string myQuery, string ConnStr)
{
OleDbDataAdapter oda = new OleDbDataAdapter (myQuery, ConnStr);
DataSet ds = new DataSet();
oda.Fill(ds);
foreach(DataRow pRow in ds.Tables[0].Rows){
_currentQuest.question=pRow["question"].ToString();
_currentQuest.questionNumber =Convert.ToInt16(pRow["questionnumber"]);
_currentQuest.rightAnswer=pRow["answer"].ToString();
_currentQuest.goodFeedBack=pRow["goodfeedback"].ToString();
_currentQuest.badFeedBack1=pRow["badfeedback1"].ToString();
_currentQuest.badFeedBack2=pRow["badfeedback2"].ToString();
AllQuestions.Add(_currentQuest);
}
return ds;
}
我得到的錯誤是:
對象引用不設置到對象的實例。
這個錯誤是什麼意思?問題是什麼?
錯誤發生在上面的哪一行代碼? – Dinesh 2012-02-29 12:07:36