初学,正在做练习,遇到问题!DataSet ds=new DataSet ();ds里有从数据库里查询来的一个表的记录IList il=ds.Tables[0].DefaultView as IList;表的第一列是int型数据,列名“id”;int id=??????这里该怎样得到 IList 中第一行第一列的数据呢????

解决方案 »

  1.   


    IList il=ds.Tables[0].DefaultView as IList;//1
    // 也可以写成:
    IList<DataRow> il = ds.Tables[0].DefaultView as IList; //2//1
    int id = Convert.ToString((DataRow)il[0][0]) ;//2
    int id = Convert.ToString(il[0][0]);试下吧
      

  2.   


    不行!!!!!IList<DataRow> il = ds.Tables[0].DefaultView as IList;这一句报错!!编译器错误信息: CS0308: 非泛型 类型“System.Collections.IList”不能与类型参数一起使用
      

  3.   


    IList il=ds.Tables[0].DefaultView as IList;;
    变量 = ((DataRowView)il[0])[0];
    上面的就是你想要的啊!
      

  4.   


    变量 = ((DataRowView)il[0])[0];
    补充:
    string sss=((DataRowView)il[0])[0].toString();
    太感谢了!!!!!
      

  5.   

         List<类型名> list = new List<类型名>();
               DataTable dt = (DataSet ds=new DataSet ();ds里有从数据库里查询来的一个表的记录,返回ds.tables[0])
               foreach(DataRow dr in dt.Rows){
                    类型名 对象名=new 类型名(); 
                    (举个例子)
                      Book bk =new Book(); 
                   bk.Id = (int)dr["id"];
                   这样可以将数据放入list 剩下的会了吗?
                    }