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 ...
随机推荐
- day2:vcp考试
Q21. An administrator has been instructed to secure existing virtual machines in vCenter Server.Whic ...
- vue2.0 tab切换几种方式
第一种 比较灵活简单的方式(切换改变部分的内容在组件中比较方便操作) <template> <div id="app"> <ul> <li ...
- java Arrays.asList用法
java Arrays.asList用法 用途 Arrays是java容器相关操作的工具类,asList方法将Array转换为list,是Array和List之间的桥梁. 注意 Arrays.asLi ...
- PAT 1047 编程团体赛(代码)
1047 编程团体赛(20)(20 分) 编程团体赛的规则为:每个参赛队由若干队员组成:所有队员独立比赛:参赛队的成绩为所有队员的成绩和:成绩最高的队获胜. 现给定所有队员的比赛成绩,请你编写程序找出 ...
- [SoapUI] 配置默认环境的properties
<Envs> <Env id="Live,Default environment"> <Project> <CusProperty nam ...
- shiro + struts2 在action 中使用 shiro 注解 @requiresPermissions 报错: 方法找不到,类初始失败
06:36:34,405 ERROR http-8084-2 dispatcher.Dispatcher:38 - Exception occurred during processing reque ...
- /^\s+|\s+$/g 技术 内容
alert(" aa dd ".replace(/^\s+|\s+$/g,'')+"方式的"); //正则表达式解释:分成两部分,^\s+ 以空格开头,\s+$ ...
- 用pyqt5做一个能python程序能插入图片的ide
之前只是放到github上了,现在一想应该开源,大家想继续做好这个ide的都能从这里起步. #注意在.py文件相同目录下放一个1.png做测试图片 #本质就是用html来实现图片 #写在前面的话:这个 ...
- 2018.07.20 atcoder Largest Smallest Cyclic Shift(贪心)
传送门 题意:给你x个a,y个b,z个c,显然这些字符可以拼成若干字符串,然后求这些字符串中最小表示法表示出来的最大的那一个. 解法:贪心思想,用multiset维护现在拼成的字串,每次取一个最小的和 ...
- dev ChartControl 备忘
一个chartControl 里包括以个diagram(图表) diagram里可以设置 x-axis与y-axis ,另外还可以设置SecondaryXAxis与SecondaryYAxis,在Se ...