日期:2014-05-17  浏览次数:20434 次

linq怎么去取datatable某一列所有数据,我要返回给一个list<string>
linq怎么去取datatable某一列所有数据,我要返回给一个list<string>
linq datatable 某一列所有数据

------解决方案--------------------
            var list = dt.AsEnumerable().Select(t => t.Field<string>("列名")).ToList();

------解决方案--------------------
/*遍历DataTable*/
        class ClientStruct
        {
            public string ID = "ID";
            public string Name = "Name";
            public string Company = "Company";
            public string CreatedDate = "CreatedDate";
        }

        public string[,] infoArr = new string[,] { { "1", "百度", "baidu", "201303" }, { "2", "迅雷", "xunlei", "201302" }, { "3", "谷歌", "guge", "201301" } };
        protected void LinqDataTable()
        {
            DataRow row;
            ClientStruct cs = new ClientStruct();
            DataTable dtTable = new DataTable();
            dtTable.Columns.Add(cs.ID);
            dtTable.Columns.Add(cs.Name);
            dtTable.Columns.Add(cs.Company);
            dtTable.Columns.Add(cs.CreatedDate);
            for (int i = 0; i < 3; i++)
            {
                row = dtTable.NewRow();
                row[cs.ID] = infoArr[i, 0];
                row[cs.Name] = infoArr[i, 1];
                row[cs.Company] = infoArr[i, 2];
                row[cs.CreatedDate] = infoArr[i, 3];
                dtTable.Rows.Add(row);
            }

            //遍历DataTable,取出所有的ID
       &nb