Compare a datarow with a string

0

Good morning I have the following code for the generation of an excel file in c #

int i = 5;
int f = 0;   
foreach (DataRow Row in DS.Tables[0].Rows)
{
    f = f + 1;
    // Asignar los valores de los registros a las celdas
    HojaExcel.Cells[i, "A"] = f;
    HojaExcel.Cells[i, "B"] = Row.ItemArray[0];
    HojaExcel.Cells[i, "C"] = Row.ItemArray[1];
    HojaExcel.Cells[i, "D"] = Row.ItemArray[2];
    HojaExcel.Cells[i, "E"] = Row.ItemArray[3];
    HojaExcel.Cells[i, "F"] = Row.ItemArray[4];
    HojaExcel.Cells[i, "G"] = Row.ItemArray[5];
    HojaExcel.Cells[i, "H"] = Row.ItemArray[6];
    HojaExcel.Cells[i, "I"] = Row.ItemArray[7];
    if (Row.ItemArray[7] == "REALIZADO")
    {
         HojaExcel.Cells[i, "G"] = "0";
    }
    // Avanzamos una fila
    i++;
}

I am trying to do a check based on the last column that I would not know if it is the correct way or not to validate it, but in the end I want that if the data contained in the column I I have typed Done in the G column, enter the number 0.

Thank you in advance for your cooperation.

Cordial greetings.

    
asked by Carrobe90 23.10.2017 в 18:15
source

1 answer

0

The only thing you need to do is add the conversion ToString of the element:

if (Row.ItemArray[7].ToString() == "REALIZADO")...

Although incidentally, you could also change the evaluation like this:

if (Row.ItemArray[7].ToString().Equals("REALIZADO"))...
    
answered by 23.10.2017 / 18:36
source