I have a DataTable that has been created with the same columns as another DataTable.
DataTable dtAux = new DataTable();
for (int i = 0; i < dt.Columns.Count; i++)
{
dtAux.Columns.Add(dt.Columns[i].ToString(), dt.Columns[i].GetType());
}
Later I want to add records to the dtAux dataTable, depending on whether they meet certain requirements
for (int i = 0; i < dgvAux.Rows.Count; i++)
{
foreach (DataRow dr in dt.Rows)
{
if ((dr[0].ToString() == dgvAux.Rows[i].Cells[0].Value.ToString()))
{
DataRow drAux = dtAux.NewRow();
drAux[0] = ((drAux[0].GetType()) (dr[0].ToString()));
...
...
...
dtAux.Rows.Add(drAux);
}
}
}
The problem arises when I try to put in dr[0]
the value, previously cast, I can not get it right