0

我有这个 SQL 查询

cmd.CommandText = "SELECT [tblStudent]![LastName] & ', ' & [tblStudent]![FirstName] & ' ' & [tblStudent]![MiddleName] AS FullName," & _
" tblGrade.FirstGrading, tblGrade.SecondGrading, tblGrade.ThirdGrading, tblGrade.FourthGrading," & _
" Avg(b.GradeValue) AS AverageGrade" & _
" FROM ((((tblGrade INNER JOIN tblEnrolment ON tblGrade.EnrolmentID=tblEnrolment.EnrolmentID)" & _
    " INNER JOIN tblStudent ON tblStudent.StudentID=tblEnrolment.StudentID)" & _
    " INNER JOIN tblSubjectOffering ON tblSubjectOffering.SubjectOfferingID=tblGrade.SubjectOfferingID)" & _
    " INNER JOIN tblSubject ON tblSubject.SubjectID=tblSubjectOffering.SubjectID)" & _
    " INNER JOIN tblSection ON tblSection.SectionID=tblSubjectOffering.SectionID" & _
" WHERE tblSection.SectionTitle='" & s(0) & "' AND tblSubject.SubjectID='" + s2(0) + "'" & _
" GROUP BY [tblStudent]![LastName] & ', ' & [tblStudent]![FirstName] & ' ' & [tblStudent]![MiddleName], tblGrade.FirstGrading, tblGrade.SecondGrading, tblGrade.ThirdGrading, tblGrade.FourthGrading" & _
" ORDER BY [tblStudent]![LastName] & ', ' & [tblStudent]![FirstName] & ' ' & [tblStudent]![MiddleName]"

这段代码给了我一个运行时错误“一个或多个必需参数没有值”。

4

2 回答 2

2

我的预感是 Access 认为b.GradeValue是一个参数,因为没有表名或别名b

Avg(b.GradeValue) AS AverageGrade

我建议您Debug.Print完成SELECT语句,或将其写入文本文件,然后在 Access 查询设计器中将其作为新查询进行测试。当它要求您提供参数值时,它还会向您显示它认为是参数的任何内容的“名称” 。

于 2013-10-14T18:57:54.213 回答
1

很难仅使用 SQL 语句提供建议,与您的其他代码和对象脱节。

就目前而言,我看到了两个主要的潜在问题。首先是您有Avg(b.GradeValue),但在命令的其他地方没有引用该b表。为此,您需要删除b或确保引用有效。

其次,您有两个变量,s()它们s2()可能返回无效或空数据。您可能需要调试此步骤并在继续执行之前检查每个保持的值,然后在代码的另一部分中修复问题(如果有问题)。

于 2013-10-14T18:58:57.240 回答