You need to move the validity test outside the loop so the success message only appears if all rows are true.
bool chValidity = true;
for (int i = 1; i < rowCount; i++)
{
DateTime d;
chValidity = DateTime.TryParseExact(
worksheet.Cells[i + 1, 1].Value.ToString(),
"MM/dd/yyyy h:mm:ss",
if (chValidity == false)
{
cell1.Text = worksheet.Cells[i + 1, 1].Value.ToString() + " " + worksheet.Cells[i + 1, 2].Value.ToString() + " " + worksheet.Cells[i + 1, 2].Value.ToString() + " Baris ke " + i;
row.Cells.Add(cell1);
myTable.Rows.Add(row);
File.AppendAllText("E:\\test.txt", label1.Text);
}
}
if (chValidity == true){
label1.Text="Suskses";
}
[edit]
Removed extra condition test in the
for
statement.
[/edit]