case when answer_pic is null then 0 else 1 end  

answer_pic为数据库表中图片(image)字段

//检索数据库中图片字段是否为空,
//0表示改字段为空
public int stuanswerhasPic(int paper_id, string stu_id, int qid)
{

string sqlString = "select return_id = case when answer_pic is null then 0 else 1 end from paper_done where paper_id=" + paper_id + " and stu_id='" + stu_id + "' and qid = " + qid;
SqlConnection con = DB.getConnection();
SqlCommand mycommd = new SqlCommand(sqlString, con);
SqlDataReader myReader = mycommd.ExecuteReader();
if (myReader.Read())
{
return Convert.ToInt32(myReader["return_id"]);
}
else
{
return 0;
}
}

关键sql语句:select return_id = case when answer_pic is null then 0 else 1 end from paper_done
其中answer_pic是图片字段 paper_done是存放图片字段的表

posted on 2009-01-02 09:14  曾文亮  阅读(302)  评论(0编辑  收藏  举报