方法一:

 //DataSet转换成List<ArticleInfo>
public List<ArticleInfo> GetArticleList(DataSet ds)
{
List<ArticleInfo> list = new List<ArticleInfo>();
for (int i = ; i < ds.Tables[].Rows.Count; i++)
{
ArticleInfo model = new ArticleInfo();
model.arttime = Convert.ToDateTime(ds.Tables[].Rows[i]["arttime"]);
model.cgyid = Convert.ToInt32(ds.Tables[].Rows[i]["cgyid"]);
model.clicks = Convert.ToInt32(ds.Tables[].Rows[i]["clicks"]);
model.contents = Convert.ToString(ds.Tables[].Rows[i]["contents"]);
model.id = Convert.ToInt32(ds.Tables[].Rows[i]["id"]);
model.img = Convert.ToString(ds.Tables[].Rows[i]["img"]);
model.recommend = Convert.ToBoolean(ds.Tables[].Rows[i]["recommend"]);
model.related = Convert.ToBoolean(ds.Tables[].Rows[i]["related"]);
model.title = Convert.ToString(ds.Tables[].Rows[i]["title"]);
model.uid = Convert.ToInt32(ds.Tables[].Rows[i]["uid"]);
list.Add(model);
}
return list;
}

方法二:

  public List<ArticleInfo> DataSetToList(DataSet ds)
{
List<ArticleInfo> list = new List<ArticleInfo>();
foreach (DataRow row in ds.Tables[].Rows)
{
list.Add(DataRowToModel(row));
}
return list;
}
        /// <summary>
/// 得到一个对象实体
/// </summary>
public ArticleInfo DataRowToModel(DataRow row)
{
ArticleInfo model = new ArticleInfo();
if (row != null)
{
if (row["id"] != null && row["id"].ToString() != "")
{
model.id = int.Parse(row["id"].ToString());
} if (row["contents"] != null)
{
model.contents = row["contents"].ToString();
} if (row["cgyid"] != null && row["cgyid"].ToString() != "")
{
model.cgyid = int.Parse(row["cgyid"].ToString());
} if (row["title"] != null)
{
model.title = row["title"].ToString();
} if (row["arttime"] != null && row["arttime"].ToString() != "")
{
model.arttime = DateTime.Parse(row["arttime"].ToString());
} if (row["uid"] != null && row["uid"].ToString() != "")
{
model.uid = int.Parse(row["uid"].ToString());
} if (row["recommend"] != null && row["recommend"].ToString() != "")
{
if ((row["recommend"].ToString() == "") || (row["recommend"].ToString().ToLower() == "true"))
{
model.recommend = true;
}
else
{
model.recommend = false;
}
}
if (row["img"] != null)
{
model.img = row["img"].ToString();
} if (row["clicks"] != null && row["clicks"].ToString() != "")
{
model.clicks = int.Parse(row["clicks"].ToString());
} if (row["related"] != null && row["related"].ToString() != "")
{
if ((row["related"].ToString() == "") || (row["related"].ToString().ToLower() == "true"))
{
model.related = true;
}
else
{
model.related = false;
}
} }
return model;
}

DataSet转换成List<>的更多相关文章

  1. 把DataSet转换成JSON

    /// <summary> /// dataTable转换成Json格式 /// </summary> /// <param name="dt"> ...

  2. .net 数据源DataSet 转换成模型

    /// <summary> /// DataSet转换成model 自动赋值返回集合 /// </summary> /// <typeparam name="T ...

  3. 将DataSet转换成json

     /// <summary>        /// 把dataset数据转换成json的格式        /// </summary>        /// <para ...

  4. dataTable/dataSet转换成Json格式

    using System.Text;using System.Collections.Generic; 1)dataTable转Json(表格有名称:dt.TableName) public stat ...

  5. asp.net如何将DataSet转换成josn并输出

    public class JsonUtil { public string ToJson(DataSet dataSet) { string jsonString = "{"; f ...

  6. 将DataSet(DataTable)转换成JSON格式(生成JS文件存储)

    public static string CreateJsonParameters(DataTable dt) { /**/ /**/ /**/ /* /*********************** ...

  7. DataTabel DataSet 对象 转换成json

    public class DataTableConvertJson    { #region dataTable转换成Json格式        /// <summary>         ...

  8. sparksql 用反射的方式将rdd转换成dataset/dataframe

    java public class ReflectionDemo { private static SparkConf conf = new SparkConf().setAppName(" ...

  9. DataSet 反射转换成 List<T>

    /// <summary> /// DataSet转换成指定返回类型的实体集合 /// </summary> /// <typeparam name="T&qu ...

随机推荐

  1. Frog and Portal(思维好题)

    Frog and Portal https://hihocoder.com/problemset/problem/1873 时间限制:1000ms 单点时限:1000ms 内存限制:512MB 描述 ...

  2. Dreamweaver 调字体大小

    编辑--首选参数--字体 这里是指调代码字体的大小,就是为了编码时看的清楚些

  3. snowflake自增ID算法 (PHP版)

    /** * SnowFlake ID Generator * Based on Twitter Snowflake to generate unique ID across multiple * da ...

  4. APScheduler 浅析

    前言 APScheduler是python下的任务调度框架,全程为Advanced Python Scheduler,是一款轻量级的Python任务调度框架.它允许你像Linux下的Crontab那样 ...

  5. [BAT]操作系统定时任务调用批处理忽略error继续运行的方法

    如下,通过forfiles删除7天以前生成的一些文件,当不存在满足搜索条件的文件时,就会报错:ERROR: No files found with the specified search crite ...

  6. javascript 字符数组转换成以逗号隔开的字符串

    var ids = [];angular.forEach(pulsarServers,function (server) { ids.push(server.id);});ids = ids.join ...

  7. delete千万级别大表中的某部分数据

    如果表很大--千万级别的数据,又不能做truncate 操作,只能 delete 表中某部分数据时可以用以下来执行,这种方式只对大表操作时比较有效率,数据量小时不考虑 --示例如下 declare c ...

  8. Android传感器——加速度传感器

    步骤如下: 1. 调用Context的getSystemService(Context.SENSOR_SERVICE)方法获取SensorManager,SensorManager对象代表系统的传感器 ...

  9. jQueryUI datepicker 报错: TypeError: inst is undefined

    前提:要引用的js等都引用好了 调用日期控件的input: <input id="starttime" name="starttime" class=&q ...

  10. Necklace

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...