-3

I have 3 projects working fine separately but now I need to combine them in one file and I did it. Now I'm facing problem at the time of sending email after executing the query. Query works fine and there is no problem. I could't understand where is the problem in my code?

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 +@"' 
                                  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 +@"' 
                                  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 });
    }

I am getting NullReferenceException in IF condition after executing the query.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • Is the UpdateCommand object being instantiated before that block code? How are you creating the adapter? – elvin Oct 27 '14 at 05:48
  • You shouldn't build SQL queries using strings like that, as they are vurnerable to SQL injection. Use parameters instead. – Rik Oct 27 '14 at 07:53
  • 1
    [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Rik Oct 27 '14 at 08:03
  • Please add the full exception, message and stack trace. – abto Oct 27 '14 at 08:18
  • It's impossible to help given the limited info. Luckily, it should be easy for *you* to fix by stepping through the code in debugger and seeing what's Null. Could be dsMove, table dirData, etc. – mr_plum Oct 27 '14 at 21:24

1 Answers1

0

Thank you very much nunzabar. I got where the problem was? There are three custom datasets created and I forget to set one dataset name to match with "dirdata".

Community
  • 1
  • 1