我想使用案例条件显示我的数据。 现在在我的数据库中:
Id MoodHappy MoodSad
1 1 0
我想检索此值,但我不想显示为1或0。 我想显示如果选择了id 1并且moodhappy等于1则显示happy。
"Select moodHappy, case when moodHappy = 1 then 'Happy' end as moodlvl from Mood";
SqlDataReader myReader = cmd.ExecuteReader();
addScholarship userObj = new addScholarship();
while (myReader.Read())
{
string moody = myReader["moodHappy"].ToString();
userObj = new addScholarship(moody);
}
myReader.Close();
return userObj;
结果仍显示1并且不满意
答案 0 :(得分:0)
Select moodHappy, case when moodHappy = 1 then 'Happy' else 'Sad' end as moodlvl from Mood
SqlDataReader myReader = cmd.ExecuteReader();
addScholarship userObj = new addScholarship();
while (myReader.Read())
{
string moody = myReader["moodlvl "].ToString();
userObj = new addScholarship(moody);
}
myReader.Close();
return userObj;