I'm developing a system that looks for information in an excel and does some processing to save the data in a DBF database. All the treatments I do are on top of DataTables, so I use dataRows and after a certain time, I'm facing many problems with the following error:
I've researched some solutions, but I've done a query between two dataTables.
var dtJoin = from dtOri in dbCons.getDataTable("\ArqDbf.DBF").AsEnumerable()
join dtFKey in dbCons.getDataTable("\ArqDbf.DBF").AsEnumerable()
on dtOri["prnt_ent"] equals dtFKey["org_ent_id"]
select dtJoinOrg.LoadDataRow(new object[]
{
dtOri["org_ent_id"],
dtOri["org_ent_nm"],
dtOri["org_en_des"],
dtOri["prnt_ent"],
dtFKey["org_ent_nm"],
dtFKey["org_en_des"]
},false);
dtOrgs.TableName = "Orgs";
foreach (DataRow drJoin in dtJoin)
{
dtJoinOrg.Rows.Add(drJoin);
}
And at the point where I do the "dtJoinOrg.Rows.Add" it gives this error, but where does the dataRow bind to a dataTable? How can I resolve this problem?
About dataRow belonging to a dataTable, I've created the following workaround:
/*
Nesse caso o pDtClone tem a mesma estrutura do pDtOri.
Caso alguem se pergunte por que estou fazendo isso,
é que há um tratamento durante a execução em que poderei alterar as
informações do pDtClone e depois vou comparar com o pDtOri
*/
DataRow[] drResult = pDtOri.Select(vWhere);
if (drResult.Length > 0)
{
for (int i = 0; i < drResult.Length; i++)
{
DataRow drNew = pDtClone.NewRow();
try
{
int vColIndex = 0;
foreach (object vValue in drResult[0].ItemArray)
{
drNew[vColIndex] = vValue;
vColIndex++;
}
pDtClone.Rows.Add(drNew);
}
finally
{
drNew = null;
}
}
}
This is a solution I have found so far, but I would like to see other solutions.