Skip to content

Instantly share code, notes, and snippets.

@Generickle
Created December 14, 2018 19:02
Show Gist options
  • Save Generickle/2faa7db952e492ee8a14c7fd5815a46c to your computer and use it in GitHub Desktop.
Save Generickle/2faa7db952e492ee8a14c7fd5815a46c to your computer and use it in GitHub Desktop.
private DataTable ProductoCartesiano(NodoTabla tabla1, NodoTabla tabla2)
{
DataTable resultado = new DataTable(tabla1.TableName + "-" + tabla2.TableName);
int i = 0;
foreach (DataColumn campo in tabla1.Columns)
{
resultado.Columns.Add(tabla1.TableName+"."+tabla1.Columns[i].ColumnName);
i++;
}
i = 0;
foreach (DataColumn campo in tabla2.Columns)
{
resultado.Columns.Add(tabla2.TableName + "."+tabla2.Columns[i].ColumnName);
i++;
}
for (int j = 0; j < tabla1.Rows.Count; j++)
{
for (int k = 0; k < tabla2.Rows.Count; k++)
{
DataRow registro = resultado.NewRow();
int posicion = 0;
for (int l = 0; l < tabla1.Columns.Count; l++)
{
registro[posicion] = tabla1.Rows[j].ItemArray[l];
posicion++;
}
for (int l = 0; l < tabla2.Columns.Count; l++)
{
registro[posicion] = tabla2.Rows[k].ItemArray[l];
posicion++;
}
resultado.Rows.Add(registro);
}
}
return resultado;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment