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;
}