Ilist转换成dataset

来源:互联网 发布:4钻淘宝店铺转让价格 编辑:程序博客网 时间:2024/04/30 11:07
导读:
  转换成DataSet的通用的方法如下:
  PrivateFunctionConvertToDS(ByVallst AsIList, ByValtyp AsSystem.Type) AsDataSet
  Dimobj AsObject
  Dimds AsNewDataSet
  
  Dimtbl AsDataTable = ds.Tables.Add(typ.Name)
  
  ' Get the public properties.
  DimmyPropertyInfo AsSystem.Reflection.PropertyInfo() = typ.GetProperties((System.Reflection.BindingFlags.Public OrSystem.Reflection.BindingFlags.Instance))
  
  
  Dimpi AsSystem.Reflection.PropertyInfo
  ForEachpi InmyPropertyInfo
  tbl.Columns.Add(pi.Name, System.Type.GetType(pi.PropertyType.ToString()))
  Next
  
  
  ForEachobj Inlst
  Dimdr AsDataRow = tbl.NewRow
  
  ForEachpi InmyPropertyInfo
  dr(pi.Name) = pi.GetValue(obj, Nothing)
  Next
  tbl.Rows.Add(dr)
  
  Next
  Returnds
  EndFunction
  使用上面的方法来生成DataSet的方法如下:
  DimCust AsNewCustomerBR
  DimcustomerLst AsIList
  customerLst = Cust.GetCustomers("from Customers")
  
  DimmyType AsSystem.Type = GetType(Customers)
  DataGrid1.DataSource = ConvertToDS(customerLst, myType).Tables(0)
  posted on 2006-06-14 13:18 Vinson阅读(662) 评论(0) 编辑 收藏

本文转自
http://mhx1982.cnblogs.com/archive/2006/06/14/425686.aspx
原创粉丝点击