Get a column value from a datatable

  • Thread starter Microsoft News Group
  • Start date
M

Microsoft News Group

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;

}

}
 
M

Microsoft News Group

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 said:
if(row["Min"].Equals(0))

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

return Convert.ToInt32(row["Min"]) == 0;
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top