判断如果数据查询不到的话 就不要输出
public string getStuName(string StuID)
{
return DbHelper.ExecuteScalar("select TrueName from [CNVP_User] where UserID =" + StuID).ToString();
}
这个如果数据查询不到的话就出错 帮我改下 判断如果数据查询不到的话 就不要输出
[解决办法]
Object o = DbHelper.ExecuteScalar("select TrueName from [CNVP_User] where UserID =" + StuID); //去掉.ToString()
if(o==null){return "";}else{return o.ToString();} //有值再返回.ToString();
[解决办法]
try:
public string getStuName(string StuID)
{
return Convert.ToString(DbHelper.ExecuteScalar("select TrueName from [CNVP_User] where UserID =" + StuID));
}