I'm trying to pass a column from one datagridview to another and I need to add more days, but at the time of making the conversion and showing it on the other table I get the following error.
System.InvalidCastException' en mscorlib.dll
Información adicional: Object cannot be cast from DBNull to other types.
My code is as follows:
DateTime? ini;
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
dataGridView7.Rows.Add(DBNull.Value);
dataGridView7.Rows.Add(ds.Tables[0].Rows[i]["Required Date"]);
ini = Convert.ToDateTime(ds.Tables[0].Rows[i]["Required Date"] );
ini = ini.Value.AddDays(75);
//MessageBox.Show( String.Format("{0:dd/MM/yyyy}",ini));
dataGridView7.Rows.Add(String.Format("{0:dd/MM/yyyy}", ini));
}
The error marks me on the next line
ini = Convert.ToDateTime(ds.Tables[0].Rows[i]["Required Date"] );
I do not know how you can enter the same null that you have in the original datagridview. Thanks