locked
DataSet RRS feed

  • Question

  • User-1499457942 posted

    Hi

      I have below code . I want value should not be null and > 0 

    if (dt.Rows[i]["Amount"] != DBNull.Value

    Thanks

    Wednesday, August 29, 2018 6:35 AM

Answers

  • User-369506445 posted

    you have to first check for a valid number, then check for ><g class="gr_ gr_3 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" id="3" data-gr-id="3">0  ,</g> please try below code

      if (!string.IsNullOrEmpty(dt.Rows[i]["Amount"]))
                {
                    int num;
                    if (int.TryParse(dt.Rows[i]["Amount"], out num))
                    {
                        if (int.Parse(dt.Rows[i]["Amount"])>0)
                        {
                          // put your code here 
                        }
                    }
                }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 29, 2018 7:14 AM

All replies

  • User-369506445 posted

    hi

    you can try below code for check empty and null

     if (!string.IsNullOrEmpty(dt.Rows[i]["Amount"]))
                {
                }

    Wednesday, August 29, 2018 6:50 AM
  • User-1499457942 posted

    Hi

      WIll it also check that value is > 0 . In Database there is already value 0 . I want when value is > 0 then only calculation done

    Thanks

    Wednesday, August 29, 2018 6:55 AM
  • User-369506445 posted

    you have to first check for a valid number, then check for ><g class="gr_ gr_3 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" id="3" data-gr-id="3">0  ,</g> please try below code

      if (!string.IsNullOrEmpty(dt.Rows[i]["Amount"]))
                {
                    int num;
                    if (int.TryParse(dt.Rows[i]["Amount"], out num))
                    {
                        if (int.Parse(dt.Rows[i]["Amount"])>0)
                        {
                          // put your code here 
                        }
                    }
                }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 29, 2018 7:14 AM
  • User-1499457942 posted

    Hi

      Field will have valid number. I want to check that Value is greater than 0 or not. So only this line will work

    if (int.Parse(dt.Rows[i]["Amount"])>0)

    I tried below is it ok
    Convert.ToInt32(dt.Rows[i]["Amount"]) > 0

    Thanks
    Wednesday, August 29, 2018 8:09 AM
  • User-369506445 posted

    yes, if you only want to check greater than 0 or <g class="gr_ gr_38 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" id="38" data-gr-id="38">not  <g class="gr_ gr_37 gr-alert gr_gramm gr_inline_cards gr_run_anim Style replaceWithoutSep" id="37" data-gr-id="37">,</g></g><g class="gr_ gr_37 gr-alert gr_gramm gr_inline_cards gr_disable_anim_appear Style replaceWithoutSep" id="37" data-gr-id="37">you</g> can use 

    if (Convert.ToInt32(dt.Rows[i]["Amount"]) > 0)
    {
    }

    Wednesday, August 29, 2018 9:21 AM