/// <summary> /// 得到一个对象实体 /// </summary> public Model.UserAnswer DataRowToModel(DataRow row) { Model.UserAnswer model = new Model.UserAnswer(); if (row != null) { if (row["QuestionID"] != null) { model.QuestionID = long.Parse(row["QuestionID"].ToString()); } if (row["UserID"] != null) { model.UserID = long.Parse( row["UserID"].ToString()); } if (row["Orders"] != null ) { model.Orders = 0; } if (row["Answer"] != null && row["Answer"].ToString() != "") { model.Answer = row["Answer"].ToString().Split('|'); } } return model; }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.UserAnswer GetModel(long QuestionID, long UserID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select QuestionID,UserID,Orders,Answer from UserAnswer"); strSql.Append(" where QuestionID=@QuestionID and UserID=@UserID limit 1"); MySqlParameter[] parameters = { new MySqlParameter("@QuestionID", MySqlDbType.Int64), new MySqlParameter("@UserID", MySqlDbType.Int64), }; parameters[0].Value = QuestionID; parameters[1].Value = UserID; Model.UserAnswer model = new Model.UserAnswer(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }