香小莫微博:请懂sql的大哥帮下小弟?

来源:百度文库 编辑:中科新闻网 时间:2024/05/09 14:50:13
public bool DeleteScore(int iScoreId, int iStudentId, int iSubjectId, int iClassId)
{
string sql = "delete from Score where 1=1";
if(iScoreId != -1)
{
sql = sql + " and ScoreId="+iScoreId;
}
if(iStudentId != -1)
{
sql = sql + " and studentid="+iStudentId;
}
if(iSubjectId != -1)
{
sql = sql + " and CourseID in (select CourseID from Course where SubjectID ="+iSubjectId+")";
}
if(iClassId != -1)
{
sql = sql + " and StudentID in (select StudentID from Student where ClassID="+iClassId+")";
}
try
{
cDbObject.Execute(sql);
}
catch(Exception e)
{
throw(e);
}
return true;
}
代码我能看懂,是做不确定条件查询
请问if(iScoreId != -1)是什么意思?
iscoreid本来就是int类型可以是-1呀
是不是没有值就是-1呀?
谢谢
兄弟,假如我传进来的值刚好是-1呢?

iScoreId是作为一个参数出现的
iScoreId != -1 就代表输入参数有效时
加以判断