Get a column value from a datatable

Discussion in 'ASP .Net' started by Microsoft News Group, Sep 22, 2006.

  1. I am trying to get a value from the MIN column in my database. I can not
    seem to get the IF statement to be true, even thou my debugging says the
    column value is 0, but it is not hitting the return true. Is there anyway
    to get the column value to test it to equal zero.



    public static bool GetPriceRangesByMin()

    {



    using(DataTable table = GetPriceRanges())

    {

    foreach (DataRow row in table.Rows)

    {


    if(row["Min"].Equals(0))


    {


    return true;

    }

    }

    return false;

    }

    }
     
    Microsoft News Group, Sep 22, 2006
    #1
    1. Advertising

  2. Microsoft News Group

    Mark Rae Guest

    "Microsoft News Group" <> wrote in message
    news:%...

    > if(row["Min"].Equals(0))


    Ah yes, but what datatype is "Min"? Try this:

    return Convert.ToInt32(row["Min"]) == 0;
     
    Mark Rae, Sep 22, 2006
    #2
    1. Advertising

  3. Thanks, I used this.

    // Convert "Min" field to a decimal.

    value = row["Min"].ToString();

    intValue = Decimal.Parse(value);



    But now I am trying to change a null value of a datatable, because a row
    contains a null value and it doesnt like it. I am trying to do this.

    table[0].Rows[0].ItemArray[6] = String.Empty;

    But it is not replacing the item in the datatable. Any other ways to do
    this. I know theres a SetColumnNameNull(), but that didnt work.

    "Mark Rae" <> wrote in message
    news:%...
    > "Microsoft News Group" <> wrote in message
    > news:%...
    >
    >> if(row["Min"].Equals(0))

    >
    > Ah yes, but what datatype is "Min"? Try this:
    >
    > return Convert.ToInt32(row["Min"]) == 0;
    >
    >
     
    Microsoft News Group, Sep 24, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J. Babe
    Replies:
    1
    Views:
    8,425
    Kevin Spencer
    Aug 15, 2003
  2. jg
    Replies:
    1
    Views:
    755
    =?Utf-8?B?U2hhaWxlc2ggSmFubnU=?=
    Aug 17, 2004
  3. MattB
    Replies:
    2
    Views:
    16,429
    MattB
    Nov 11, 2005
  4. keithb
    Replies:
    1
    Views:
    4,766
  5. gbattine
    Replies:
    0
    Views:
    583
    gbattine
    Sep 6, 2006
Loading...

Share This Page