Rahul Patil

Rahul Patil

  • 1.2k
  • 183
  • 30.7k

datatable old data erase when second time foreach loop execute

Apr 29 2023 9:54 AM

my datatable old data erase when second time foreach loop execute

when second time inside foreach loop then my old data is erase

Code :

private void btnTodayUrgent_Click(object sender, EventArgs e)
{

    if (mStrSelLotCodeList != "")
    {
        //if (true)
        //{

        //}
        //DataGridViewCellStyle style = new DataGridViewCellStyle();
        //style.ForeColor = Color.Red;
        string[] StrColumns = mStrSelLotCodeList.ToString().Split(',');
        foreach (string Str in StrColumns)
        {
            //DataTable dt1 = new DataTable();
            //dt = dttableOld.Clone();
             dt = ObjBOPelAdmin.DS.Tables[ObjBOPelAdmin.StrPacketMastFill].AsEnumerable().Where(X => Val.ToString(X["LOT_CODE"]) == Str).CopyToDataTable();
            dt.AcceptChanges();
            //dt = c;
            //dt.Rows.Add(c);
            //var dataRow = dt.NewRow();
            //DataRow row = dt.NewRow();
            //dt.Rows.Add(dt1.Rows);
            //dt.ImportRow();
            //dt.Rows.Add(dt1);
            //dt.ImportRow(dt1);
            //dt.Rows.Add(dt1);
            //dt = dt1.Clone();
        }

need help


Answers (2)