C# DataSet转list<T>

DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.ConnString, CommandType.Text, Sql.ToString());
if (ds.Tables[0].Rows.Count > 0)
{
    foreach (DataRow dr in ds.Tables[0].Rows)
    {
        lst.Add(DataRowToModel(dr));
    }
    return lst;
}

转化方法:

public static oprDiary DataRowToModel(DataRow row)
{
    oprDiary model = new oprDiary();
    if (row != null)
    {
        if (row["ID"] != null && row["ID"].ToString() != "")
        {
            model.ID = int.Parse(row["ID"].ToString());
        }
        if (row["Name"] != null)
        {
            model.ChangePartName = row["Name"].ToString();
        }
	if(row["HasReturn"]!=null && row["HasReturn"].ToString()!="")
	{
	    if((row["HasReturn"].ToString()=="1")||(row["HasReturn"].ToString().ToLower()=="true"))
	    {
	        model.HasReturn=true;
	    }
	    else
	    {
	        model.HasReturn=false;
	    }
        }
    }
    return model;
}
posted @ 2021-10-16 11:32  673613920  阅读(564)  评论(0编辑  收藏  举报