贪贪博客
菜鸟级人物
   1: public IList<Point> GetAllPonitPage(int start, int limit)
   2:         {
   3:             string sql = "select top " + limit + "* from Led_Point where Id not in(select top " + start + " Id from Led_Point order by Id asc) order by Id asc";
   4:             SqlDataAdapter sda = new SqlDataAdapter(sql, "server=.;uid=sa;pwd=sa;database=Led2010");
   5:             DataSet ds = new DataSet();
   6:             sda.Fill(ds);
   7:             IList<Point> result = new List<Point>();
   8:             for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
   9:             {
  10:                 Point _t = (Point)Activator.CreateInstance(typeof(Point));
  11:                 PropertyInfo[] propertys = _t.GetType().GetProperties();
  12:                 foreach (PropertyInfo pi in propertys)
  13:                 {
  14:                     for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
  15:                     {
  16:                         // 属性与字段名称一致的进行赋值 
  17:                         if (pi.Name.Equals(ds.Tables[0].Columns[i].ColumnName))
  18:                         {
  19:                             // 数据库NULL值单独处理 
  20:                             if (ds.Tables[0].Rows[j][i] != DBNull.Value)
  21:                                 pi.SetValue(_t, ds.Tables[0].Rows[j][i], null);
  22:                             else
  23:                                 pi.SetValue(_t, null, null);
  24:                             break;
  25:                         }
  26:                     }
  27:                 }
  28:                 result.Add(_t);
  29:             }
  30:             return result;
  31:         }
posted on 2011-03-23 14:12  贪贪  阅读(377)  评论(0编辑  收藏  举报