Sofari Agali

Sofari Agali

  • 1.9k
  • 182
  • 18.6k

String was not recognized as a valid DateTime

May 12 2020 6:27 AM
Hi!
Someone to help me for this ; I have the following code in my project:
  1. public void LoadRecords()  
  2.        {  
  3.            int i = 0;  
  4.            dataGridView1.Rows.Clear();  
  5.            cn.Open();  
  6.            cm = new OleDbCommand("select * from Produit", cn);  
  7.            dr = cm.ExecuteReader();  
  8.            while (dr.Read())  
  9.            {  
  10.                i += 1;  
  11.                dataGridView1.Rows.Add(i, dr["ProdID"].ToString(), dr["nom"].ToString(), dr["Quantite"].ToString(), dr["peremption"].ToString());  
  12.   
  13.                foreach (DataGridViewRow row in dataGridView1.Rows)  
  14.                {  
  15.                                
  16.                         
  17.                    var now = DateTime.npw;  
  18.                  
  19.                    var expireDate = DateTime.Parse(row.Cells[3].Value.ToString());  
  20.                    var sixtyDayBefore = expireDate.AddDays(-1);  
  21.                    if(now > sixtyDayBefore && now > expireDate)  
  22.                    {  
  23.                        row.DefaultCellStyle.BackColor = Color.Yellow;  
  24.   
  25.                    }  
  26.                    else if(now > expireDate)  
  27.                    {  
  28.                        row.DefaultCellStyle.BackColor = Color.Red;  
  29.                    }  
  30.                }  
  31.   
  32.            }  
  33.              
  34.                cn.Close();  
  35.            dr.Close();  
  36.        }  
 

Answers (3)