locked
If Condition RRS feed

  • Question

  • User-1499457942 posted

    Hi

      Though i have no record which satisfies the below condition but still it is going in If condition

    DataSet ds = SqlDbOperation.Data("Select Count(*) from [Test] where Status = 'N'");
    if (ds.Tables[0].Rows.Count > 0)
    {
    errMessage += "Error." + " </br>";
    }

    I have changed the above code to . It is working or is there any other best way to do the same thing.

    if (Convert.ToInt16(ds.Tables[0].Rows[0].ItemArray[0]) >  0)
                    {
                        errMessage += "Error." + " </br>";
                    }

    Thanks

    Monday, November 26, 2018 10:14 AM

Answers

  • User-1716253493 posted

    It's OK, you can also do like below

    if (Convert.ToInt16(ds.Tables[0].Rows[0][0]) >  0)
    {
       errMessage += "Error." + " </br>";
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 26, 2018 11:07 AM

All replies

  • User-1716253493 posted

    You will always have 1 result, you can use if rows[0][0] greater than zero

    Or don't use select count(*), use select col1 from test

    Monday, November 26, 2018 10:23 AM
  • User-1499457942 posted

    Hi oned_gk

        Is it ok the way i have done

    Thanks

    Monday, November 26, 2018 10:34 AM
  • User-1716253493 posted

    It's OK, you can also do like below

    if (Convert.ToInt16(ds.Tables[0].Rows[0][0]) >  0)
    {
       errMessage += "Error." + " </br>";
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 26, 2018 11:07 AM
  • User1629565574 posted

    Thanks for the info. <g class="gr_ gr_49 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" id="49" data-gr-id="49">It's also helps</g> me.

    Wednesday, November 28, 2018 11:47 AM