DataSet转换成List<>
方法一:
//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<>的更多相关文章
- 把DataSet转换成JSON
/// <summary> /// dataTable转换成Json格式 /// </summary> /// <param name="dt"> ...
- .net 数据源DataSet 转换成模型
/// <summary> /// DataSet转换成model 自动赋值返回集合 /// </summary> /// <typeparam name="T ...
- 将DataSet转换成json
/// <summary> /// 把dataset数据转换成json的格式 /// </summary> /// <para ...
- dataTable/dataSet转换成Json格式
using System.Text;using System.Collections.Generic; 1)dataTable转Json(表格有名称:dt.TableName) public stat ...
- asp.net如何将DataSet转换成josn并输出
public class JsonUtil { public string ToJson(DataSet dataSet) { string jsonString = "{"; f ...
- 将DataSet(DataTable)转换成JSON格式(生成JS文件存储)
public static string CreateJsonParameters(DataTable dt) { /**/ /**/ /**/ /* /*********************** ...
- DataTabel DataSet 对象 转换成json
public class DataTableConvertJson { #region dataTable转换成Json格式 /// <summary> ...
- sparksql 用反射的方式将rdd转换成dataset/dataframe
java public class ReflectionDemo { private static SparkConf conf = new SparkConf().setAppName(" ...
- DataSet 反射转换成 List<T>
/// <summary> /// DataSet转换成指定返回类型的实体集合 /// </summary> /// <typeparam name="T&qu ...
随机推荐
- maven不存在jar包解决
win7环境 下载:https://maven.apache.org/download.cgi 提取文件,并cmd 转到bin目录 假设要添加的jar包是jbarcode-0.2.8.jar, 可执行 ...
- what's RNA-Seq?
- LaTeX 公式(转自)Iowa_Battleship 神犇
传送门 (我这个蒟蒻只是mark一下 这个LaTex公式很全!!我是照着打数学公式的!! orz大佬Iowa
- CComSafeArray
https://blog.csdn.net/tangaowen/article/details/6554640
- Hadoop 系列(一)基本概念
Hadoop 系列(一)基本概念 一.Hadoop 简介 Hadoop 是一个由 Apache 基金会所开发的分布式系统基础架构,它可以使用户在不了解分布式底层细节的情況下开发分布式程序,充分利用集群 ...
- FTP 搭建
FTP 搭建 FTP 是 File Transfer Protocol(文件传输协议)的英文简称,它工作在 0SI 模型的第七层,TCP 模型的第四屋上,即应用层. 一.FTP 简介 FTP 会话时包 ...
- hdu-1116(欧拉回路+并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1116 思路:将字符串的头元素和尾元素视为图的x,y节点,然后合并x,y. 如果这个图不连通,则门不能打 ...
- IntelliJ IDEA 2017版 使用笔记(四) 模板 live template自定义设置;IDE快捷键使用
1.File ---> setting ---->Live Template 2.添加模板 3.添加模板组 4.模板组命名 5.填写配置 6.Template ...
- Caused by: Unable to load configuration. - action - file:/C:/apache-tomcat-7.0.70/webapps/Structs/WEB-INF/classes/struts.xml:7:72 at com.opensymphony.xwork2.config.ConfigurationManager.getConfigurati
Unable to load configuration. - action - file:/C:/apache-tomcat-7.0.70/webapps/Structs/WEB-INF/class ...
- 01-html和head介绍
一.web标准 web准备介绍: w3c:万维网联盟组织,用来制定web标准的机构(组织) web标准:制作网页遵循的规范 web准备规范的分类:结构标准.表现标准.行为标准. 结构:html.表示: ...