2014-10-27 81 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”。

相关问题