Good evening everyone, I have the following conflict, I am creating two DataTable
in C#
to go through the content of two tables that are filled by means of a BD
, one shows me the code of the product and its name , and another product volumes as well as its code , I need to make a match
of both tables to show in a grid
the name of the product and the volumes of each one , and I pretend in a third DataTable
Result and store the value of the previous two, the table should look like this:
I enclose the code that I am elaborating if someone knows how to do it, I will be very grateful.
private void ValidarInfoGrid()
{
try
{
/*Objetos*/
DataTable dtProductos = new DataTable();
DataTable dtStock = new DataTable();
DataTable dtResultado = new DataTable();
/*Variables*/
int prod1 = 0;
int prod2 = 0;
int prod3 = 0;
int prod4 = 0;
int prod5 = 0;
int prod6 = 0;
int codigo = 0;
int vol1 = 0;
int vol2 = 0;
int vol3 = 0;
int vol4 = 0;
int vol5 = 0;
int vol6 = 0;
string producto = "";
/*Validaciones*/
if (cmbEstaciones!=null)
{
int estacion = 0;
estacion = (int)cmbEstaciones.SelectedValue;
if (estacion > 0)
{
dtStock = objVeederRoot.dtVolumenes(estacion);
if (dtStock.Rows.Count>0)
{
foreach (DataRow drStock in dtStock.Rows)
{
prod1 = Convert.ToInt32(drStock[0]);
vol1 = Convert.ToInt32(drStock[1]);
prod2 = Convert.ToInt32(drStock[2]);
vol2 = Convert.ToInt32(drStock[3]);
prod3 = Convert.ToInt32(drStock[4]);
vol3 = Convert.ToInt32(drStock[5]);
prod4 = Convert.ToInt32(drStock[6]);
vol4 = Convert.ToInt32(drStock[7]);
prod5 = Convert.ToInt32(drStock[8]);
vol5 = Convert.ToInt32(drStock[9]);
prod6 = Convert.ToInt32(drStock[10]);
vol6 = Convert.ToInt32(drStock[11]);
dtProductos = objVeederRoot.MuestraProductos();
foreach (DataRow drProductos in dtProductos.Rows)
{
codigo = Convert.ToInt32(drProductos[0]);
if (prod1 == codigo)
{
producto = drProductos[1].ToString();
}
if (prod2 == codigo)
{
producto = drProductos[1].ToString();
}
if (prod3 == codigo)
{
producto = drProductos[1].ToString();
}
if (prod4 == codigo)
{
producto = drProductos[1].ToString();
}
if (prod5 == codigo)
{
producto = drProductos[1].ToString();
}
if (prod6 == codigo)
{
producto = drProductos[1].ToString();
}
else
{
producto = "No Aplica";
}
}
}
objValidacion.MostrarAviso("Se cargaron los datos de forma Correcta", false, lblAviso);
}
else
{
objValidacion.MostrarAviso("No se encontraron registros, intentelo nuevamente", true, lblAviso);
}
}
}
}
catch (Exception ex)
{
ex.ToString();
}
}