首页 > 代码库 > DataTable转换为LIST

DataTable转换为LIST

  public List<string[]> SetList(DataTable dt)
        {
            List<string[]> list = new List<string[]>();
            foreach (DataRow r in dt.Rows)
            {
                int colCount = r.ItemArray.Count();
                string[] items = new string[colCount];
                for (int i = 0; i < colCount; i++)
                {
                    items[i] = Convert.ToString(r.ItemArray[i]);
                }
                list.Add(items);
            }
            return list;
        }

DataTable转换为LIST