private DataTable GetDistinctRows(DataTable dtAlredy, DataTable dtGoingToAdd)
{
try
{
string strOldFoodID = "";
for (int i = 0; i < dtAlredy.Rows.Count; i++)
{
strOldFoodID += dtAlredy.Rows[i]["Food_ID"].ToString() + ',';
}
strOldFoodID = strOldFoodID.TrimEnd(',');
string[] arrOldFoods = strOldFoodID.Split(',');
for (int index = 0; index < dtGoingToAdd.Rows.Count; index++)
{
string newFoodID = dtGoingToAdd.Rows[index]["Food_ID"].ToString();
if (!arrOldFoods.Contains(newFoodID))
{
DataRow drNewFooRow = dtAlredy.NewRow();
drNewFooRow = dtGoingToAdd.Rows[index];
dtAlredy.ImportRow(drNewFooRow);
}
}
return dtAlredy;
}
catch
{
throw;
}
}
{
try
{
string strOldFoodID = "";
for (int i = 0; i < dtAlredy.Rows.Count; i++)
{
strOldFoodID += dtAlredy.Rows[i]["Food_ID"].ToString() + ',';
}
strOldFoodID = strOldFoodID.TrimEnd(',');
string[] arrOldFoods = strOldFoodID.Split(',');
for (int index = 0; index < dtGoingToAdd.Rows.Count; index++)
{
string newFoodID = dtGoingToAdd.Rows[index]["Food_ID"].ToString();
if (!arrOldFoods.Contains(newFoodID))
{
DataRow drNewFooRow = dtAlredy.NewRow();
drNewFooRow = dtGoingToAdd.Rows[index];
dtAlredy.ImportRow(drNewFooRow);
}
}
return dtAlredy;
}
catch
{
throw;
}
}
5:35 AM |
Category: |
0
comments