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 ...
随机推荐
- Escape(状态压缩+最大流,好题)
Escape http://acm.hdu.edu.cn/showproblem.php?pid=3605 Time Limit: 4000/2000 MS (Java/Others) Memo ...
- TZOJ 4865 统计单词数(模拟字符串)
描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次数. 现在,请你编程实现这一功能,具体要求是:给定一个单词,请你输出它在给定的 ...
- Redis安装异常解决办法
官网地址:http://redis.io/ 官网下载地址:http://redis.io/download 1. 下载Redis源码(tar.gz),并上传到Linux 2. 解压缩包:tar zxv ...
- Tomcat设置默认时区
本文讲解如何在tomcat启动时设置JVM默认时区. 环境:JDK1.8.114 web容器:Tomcat 9 tomcat启动脚本 /etc/init.d/tomcat 操作系统ubuntu 16 ...
- 原生JS获取url汇总
在WEB开发中,许多开发者都比较喜欢使用javascript来获取当前url网址,本文就此为大家总结一下比较常用获取URL的javascript实现代码 URL即统一资源定位符 (Uniform Re ...
- Codeforces 691C. Exponential notation 模拟题
C. Exponential notation time limit per test: 2 seconds memory limit per test:256 megabytes input: st ...
- input不能输入中文
<input type="text" oninput="this.value = this.value.replace(/[\u4e00-\u9fa5d]/g, ' ...
- Devexpress VCL Build v2014 vol 14.2.4 发布
What's New in 14.2.4 (VCL Product Line) New Major Features in 14.2 What's New in VCL Products 14.2 ...
- 2018.07.20 bzoj2152: 聪聪可可(点分治)
传送门 本蒟蒻AC的第二道点分治,调了30min" role="presentation" style="position: relative;"&g ...
- Vim配置(转)
1.按F5可以直接编译并执行C.C++.java代码以及执行shell脚本,按“F8”可进行C.C++代码的调试 2.自动插入文件头 ,新建C.C++源文件时自动插入表头:包括文件名.作者.联系方式. ...