What is wrong?
Basically want to extract each code in each row of table “Service”
And if it is equal to specific text then set each corresponding row with matching text.
foreach (DataRow code in dsAuthors.Tables["Service"].Rows)
{
for (int i = 0; i < dsAuthors.Tables[1].Rows.Count; i++)
{
if (code[1].ToString() == "01")
{
Shipment.Rows[i][0] = "Service 1";
}
else if (code[1].ToString() == "02")
{
Shipment.Rows[i][0] = "Service 2";
}
else if (code[1].ToString() == "03")
{
Shipment.Rows[i][0] = "Service 3";
}
}
}
It just fills all rows in with Service 1 but i don’t want it to.
Sorry was NOT meant to have both tables be the same i have updated the code to be more accurate i believe.
You’re iterating over the list of rows twice. You’re reading data from the variable from the outer loop, and writing to the index from the inner loop. It’s writing “Service 1” to all rows because the last row is “01”, and the inner loop writes that to all rows.
Try this instead: