Easily Convert ArrayList To DataSet in ASP.NET

In this article, I will show you a simple trick for converting ArrayList to DataSet or DataTable so that I can filter or make a select distinct from it or Bind it to Gridview.

public DataSet ConvertArrayListToDataSet()
   {
       DataSet dsTemp = new DataSet();
       DataTable Tables = new DataTable();
       dsTemp.Tables.Add(Tables);

       dsTemp.Tables[0].Columns.Add("val", System.Type.GetType(
       "System.String"));

       foreach (string str in arraylistcontainer)
       {
           if (str != string.Empty)
           {
               DataRow myRow = dsTemp.Tables[0].NewRow();
               myRow[0] = str;
               dsTemp.Tables[0].Rows.Add(myRow);
           }

       }
   }

Please do not post any spam link in the comment box😊

Post a Comment (0)
Previous Post Next Post