2014-10-27 49 views
-3

我有3個項目單獨正常工作,但現在我需要將它們合併到一個文件中,我做到了。現在我在執行查詢後發送電子郵件時遇到了問題。查詢工作正常,沒有問題。我無法理解我的代碼中的問題在哪裏?NullReferenceException是由用戶代碼錯誤未處理

HiddenField tada = (HiddenField)item.FindControl("tada"); 

if (tada.Value == "4") 
{ 
    // approved 
    oda2.UpdateCommand.CommandText = @"update kamran.crp_mov_ord 
            set sta_flg=15, rnd_cod='" + appcode [email protected]"' 
            where mor_num='" + item["mor_num"].Text + "'"; 
    if (oda2.UpdateCommand.ExecuteNonQuery() > 0) 
    { 
     dsMove.Tables["dirdata"].Rows.Add(new object[] { item["mor_num"].Text, item["emp_nom"].Text, item["dsg_des"].Text, item["dpt_des"].Text, item["dst"].Text, item["pur_dty"].Text, item["sty_frm"].Text, item["sty_too"].Text, "Director Approved", comment, appcode }); 
    } 
} 
else 
{ 

    // approved 
    oda2.UpdateCommand.CommandText = @"update kamran.crp_mov_ord 
            set sta_flg=2, rnd_cod='" + appcode [email protected]"' 
            where mor_num='" + item["mor_num"].Text + "'"; 
    if (oda2.UpdateCommand.ExecuteNonQuery() > 0) 
    { 
     dsMove.Tables["dirdata"].Rows.Add(new object[] {tem["mor_num"].Text, item["emp_nom"].Text, item["dsg_des"].Text, item["dpt_des"].Text, item["dst"].Text, item["pur_dty"].Text, item["sty_frm"].Text, item["sty_too"].Text, "Director Approved", comment, appcode }); 
    } 

我在執行查詢後遇到IF條件的NullReferenceException。

+0

UpdateCommand對象是否在該塊代碼之前被實例化?你如何創建適配器? – elvin 2014-10-27 05:48:06

+0

您不應該使用類似的字符串來構建SQL查詢,因爲它們可以刺激SQL注入。改用參數。 – Rik 2014-10-27 07:53:34

+1

[什麼是NullReferenceException,我該如何解決它?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Rik 2014-10-27 08:03:29

回答

0

非常感謝你nunzabar。我得到了問題所在?有三個自定義數據集已創建,我忘記設置一個數據集名稱以匹配「dirdata」。

相關問題