比如说有一个
System.Collections.Generic.List<UserInfo>
但我现在不知道UserInfo的定义(当然是我不知道,程序是知道的)
然后要改为DataSet然后再把DataSet改为System.Collections.Generic.List<UserInfo>谢谢

解决方案 »

  1.   

    为什么转过来还要转回去。   /// <summary>
        ///  实现对IList到DataTable的转换
        /// </summary>
        /// <param name="ResList"></param>
        /// <returns></returns>
        public static DataTable ListToDataTable(IList<UserInfo> List)
        {
            DataSet ds = new DataSet();
            DataTable table = ds.Tables.Add("table1");
            //创建列如下:
            table.Columns.Add(new DataColumn("id", typeof(int)));//用户ID
            table.Columns.Add(new DataColumn("Name", typeof(string)));//用户姓名
             ......
             //根据list中字段创建        for (int i = 0; i < List.Count; i++)
            {
                DataRow row = table.NewRow();
                row["id"] = List[i].id;
                row["Name"] = List[i].Name;
                table.Rows.Add(row);
            }
            return table;
        }转回去应该也是遍历一遍把数据写回去吧。
      

  2.   

    为什么要这样呢,直接用就是了
    List<int> l = new List<int>();
      

  3.   

    RE:转回去应该也是遍历一遍把数据写回去吧。 
    --------------------------
    因为调用到别外一个项目的方法,他里面要的是DataSet
    RE:chinawes 
    你的代码里面
    table.Columns.Add(new DataColumn("id", typeof(int)));//用户ID
    -------------------------------
    问题我现在要的是这些东西要收程序来智能取出来
    因为我的数据库表有几十个,我的全是用List<>这种形式,
    但现在要用到别人的类他的全是DataSet
    如果我用
    table.Columns.Add(new DataColumn("id", typeof(int)));//用户ID
    这种方法的话我的全部List<>都得写
    所以想有一个智能进行转换的谢谢
      

  4.   

    RE:为什么转过来还要转回去。 
    -------------------
    因为我的是List<>他的是DataSet所以要转过去
    等取回的数据他的是DataSet我的是List<>所以要转回来谢谢
      

  5.   

    你只能逐条拷贝。遇到这样的问题,往往意味着你对ADO.NET各种ORM方法的了解有限没有使用相关的编译器帮助,或者你的数据访问层设计有问题。
      

  6.   

    我也认为是数据层的问题,2个人的数据层的确很难融合,但是无论是DataTable还是List都是列表啊