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 ...
随机推荐
- 转)ubuntu安装clang
主要参考:http://blog.csdn.net/firebird321/article/details/48528569 1.下载源码 去http://llvm.org/releases/down ...
- centos7,Python2.7安装request包
1.安装epel扩展源:“sudo yum install epel-release” 2.安装python-pip:“sudo yum install python-pip” 3.升级pip:“su ...
- TZOJ 3533 黑白图像(广搜)
描述 输入一个n*n的黑白图像(1表示黑色,0表示白色),任务是统计其中八连块的个数.如果两个黑格子有公共边或者公共顶点,就说它们属于同一个八连块.如图所示的图形有3个八连块. 输入 第1行输入一个正 ...
- mvc EF 从数据库更新实体,添加视图实体时添加不上的问题
视图对象没有一列为非null的,解决办法,在视图中,将某一列排除为null的可能,比如:isnull(te,1),即可.
- python while语句写法
count=5 while count>0: print 'i love python' count=count-1 else: print 'over'
- [SoapUI] 配置默认环境的properties
<Envs> <Env id="Live,Default environment"> <Project> <CusProperty nam ...
- Java 中>>和>>>的区别
Java 中>>和>>>的区别 Java中的位运算符: >>表示右移,如果该数为正,则高位补0,若为负数,则高位补1: >>>表示无符号右移 ...
- Dice 7 ==> dice 5
https://github.com/Premiumlab/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/Moc ...
- 二进制搭建kubernetes多master集群【一、使用TLS证书搭建etcd集群】
上一篇我们介绍了kubernetes集群架构以及系统参数配置,参考:二进制搭建kubernetes多master集群[开篇.集群环境和功能介绍] 下面本文etcd集群才用三台centos7.5搭建完成 ...
- 2018.10.05 NOIP模拟 上升序列(状压dp)
传送门 状压dp好题. 首先需要回忆O(nlogn)O(nlog n)O(nlogn)求lislislis的方法,我们会维护一个单调递增的ddd数组. 可以设计状态f(s1,s2)f(s1,s2)f( ...