Reputation: 4848
I have a datatable, transformersDT, populated with data from a database table. I'd like to check the value in a particular cell (row 0, column 6) and change that value based on what I find. How can I accomplish this in C#?
For instance, if the value is "0002" then I'd like to change it to "Conventional". Basically, I'm trying to make the values more "human readable" when viewed on the screen.
I'm trying to do something like this:
if (transformerDT.Rows[0][6] == "0002")
{
transformerDT.Rows[0][6] = "Conventional";
}
Upvotes: 1
Views: 193
Reputation: 53595
You're close:
if (transformerDT.Rows[0][6].ToString() == "0002") {
transformerDT.Rows[0][6] = "Conventional";
}
You correctly referenced the row and column but you needed to cast the cell's content to a string before you run your comparison.
Upvotes: 1
Reputation: 94625
You can use Rows
collection property of DataTable
.
object value=transformersDT.Rows[0][0]; //1st row & 1st column
Upvotes: 0