110,537
社区成员
发帖
与我相关
我的任务
分享
sb.Append(" and student.StudentName like '%@studentName%'");
不知有什么问题?
public List<Result> SearchStudentResultByGradeIdAndSubjectIdAndStudentName(string gradeId, string subjectId, string studentName)
{
StringBuilder sb = new StringBuilder();
sb.Append("select result.StudentNo,result.SubjectNo,Result.studentResult,ExamDate from "
+"Result join subject on result.SubjectNo=Subject.SubjectNo join Student on "
+"Result.StudentNo=Student.StudentNo where 1=1");
if (gradeId != "-1")
{
sb.Append(" and Subject.GradeId=@gradeId");
}
if (subjectId != "-1")
{
sb.Append(" and Subject.SubjectNo=@subjectId");
}
if (studentName != "")
{
sb.Append(" and student.StudentName like '%@studentName%'");
}
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@gradeId",gradeId),
new SqlParameter("@subjectId",subjectId),
new SqlParameter("@studentName",studentName)
};
sb.Append(" and student.StudentName like '%"+@studentName+"%'");