ASP中的SQL语法错误

时间:2017-10-19 01:34:36

标签: javascript html asp.net sql-server-2008

我正在为PowerPoint演示文稿制作一些无限循环的幻灯片。我有两张我负责的幻灯片。一个显示GPA特定括号内的学生人数Screenshot of The Graph,其工作正常

第二个图表显示每个类别(7-12)的平均GPA看起来像Average GPA Graph

代码是用HTML编写的,但是使用ASP查询SQL服务器以将数据拉到bused以使用[Canvas JS]形成图形[3]

这是我的第一个代码



<!DOCTYPE HTML>
<!-- #include virtual="/includeit/dbfunc.asp" -->

<%
	set oConn = server.createobject("ADODB.Connection")
	set oRS = server.createobject("ADODB.Recordset")
	
	call open_connection
%>

<html>
<head>
<script>
window.onload = function () {

var chart = new CanvasJS.Chart("chartContainer", {
	animationEnabled: true,
	title:{
		text: "High School GPA Brackets (MP1)"
	},
	data: [{
		type: "column",
		indexLabelFontColor: "#5A5757",
		indexLabelPlacement: "outside",
		dataPoints: [
<%
	sSQL = "SELECT count (CadetGPAs.WeightedGPA) as StudentCount " &_
			"FROM CadetGPAs INNER JOIN " &_
			"Cadets ON CadetGPAs.PropertyID = Cadets.PropertyID " &_
			"Where CadetGPAs.WeightedGPA >= 3.7 and Cadets.CurrentGrade >= 9"
			
		oRS.open SSQL, oConn
			response.write("{ label: " & chr(34) & "3.7 + " & chr(34) & ", y: " & oRS("StudentCount") & ", indexLabel: " & chr(34) & oRS("StudentCount") & chr(34) & " }, " & vbcrlf)
		oRS.close
		
	sSQL = "SELECT count (CadetGPAs.WeightedGPA) as StudentCount " &_
			"FROM CadetGPAs INNER JOIN " &_
			"Cadets ON CadetGPAs.PropertyID = Cadets.PropertyID " &_
			"Where CadetGPAs.WeightedGPA >= 3.5 and CadetGPAs.WeightedGPA < 3.7 and Cadets.CurrentGrade >= 9"
		
		oRS.open SSQL, oConn
			response.write("{ label: " & chr(34) & "3.5 - 3.7" & chr(34) & ", y: " & oRS("StudentCount") & ", indexLabel: " & chr(34) & oRS("StudentCount") & chr(34) & " }, " & vbcrlf)
		oRS.close
		
	sSQL = "SELECT count (CadetGPAs.WeightedGPA) as StudentCount " &_
			"FROM CadetGPAs INNER JOIN " &_
			"Cadets ON CadetGPAs.PropertyID = Cadets.PropertyID " &_
			"Where CadetGPAs.WeightedGPA >= 3 and CadetGPAs.WeightedGPA < 3.5 and Cadets.CurrentGrade >= 9"
		
		oRS.open SSQL, oConn
			response.write("{ label: " & chr(34) & "3.0 - 3.5" & chr(34) & ", y: " & oRS("StudentCount") & ", indexLabel: " & chr(34) & oRS("StudentCount") & chr(34) & " }, " & vbcrlf)
		oRS.close
		
	sSQL = "SELECT count (CadetGPAs.WeightedGPA) as StudentCount " &_
			"FROM CadetGPAs INNER JOIN " &_
			"Cadets ON CadetGPAs.PropertyID = Cadets.PropertyID " &_
			"Where CadetGPAs.WeightedGPA >= 2.5 and CadetGPAs.WeightedGPA < 3 and Cadets.CurrentGrade >= 9"
		
		oRS.open SSQL, oConn
			response.write("{ label: " & chr(34) & "2.5 - 3.0" & chr(34) & ", y: " & oRS("StudentCount") & ", indexLabel: " & chr(34) & oRS("StudentCount") & chr(34) & " }, " & vbcrlf)
		oRS.close
	
	sSQL = "SELECT count (CadetGPAs.WeightedGPA) as StudentCount " &_
			"FROM CadetGPAs INNER JOIN " &_
			"Cadets ON CadetGPAs.PropertyID = Cadets.PropertyID " &_
			"Where CadetGPAs.WeightedGPA >= 2 and CadetGPAs.WeightedGPA < 2.5 and Cadets.CurrentGrade >= 9"
		
		oRS.open SSQL, oConn
			response.write("{ label: " & chr(34) & "2.0 - 2.5" & chr(34) & ", y: " & oRS("StudentCount") & ", indexLabel: " & chr(34) & oRS("StudentCount") & chr(34) & " }, " & vbcrlf)
		oRS.close
		
	sSQL = "SELECT count (CadetGPAs.WeightedGPA) as StudentCount " &_
			"FROM CadetGPAs INNER JOIN " &_
			"Cadets ON CadetGPAs.PropertyID = Cadets.PropertyID " &_
			"Where CadetGPAs.WeightedGPA >= 1.5 and CadetGPAs.WeightedGPA < 2 and Cadets.CurrentGrade >= 9"
		
		oRS.open SSQL, oConn
			response.write("{ label: " & chr(34) & "1.5 - 2.0" & chr(34) & ", y: " & oRS("StudentCount") & ", indexLabel: " & chr(34) & oRS("StudentCount") & chr(34) & " }, " & vbcrlf)
		oRS.close
		
		sSQL = "SELECT count (CadetGPAs.WeightedGPA) as StudentCount " &_
			"FROM CadetGPAs INNER JOIN " &_
			"Cadets ON CadetGPAs.PropertyID = Cadets.PropertyID " &_
			"Where CadetGPAs.WeightedGPA <= 1.5 and Cadets.CurrentGrade >= 9"
		
		oRS.open SSQL, oConn
			response.write("{ label: " & chr(34) & "Less than 1.5" & chr(34) & ", y: " & oRS("StudentCount") & ", indexLabel: " & chr(34) & oRS("StudentCount") & chr(34) & " } " & vbcrlf)
		oRS.close
		
		oConn.close
					
				set oRS = nothing
				set oConn = nothing
%>

		]
	}]
});
chart.render();

}
</script>
<script type="text/javascript" src="/inc/canvasjs.min.js"></script>
</head>
<body>
	<p align=center>
	<div id="chartContainer" style="height: 98%; width: 98%;">
	</div>
</body>
</html>
&#13;
&#13;
&#13;

按预期工作,显示第一个屏幕截图中的信息

第二个完全相同,除了一个不同的select语句(我已经测试并知道一个事实有效)和标题。

&#13;
&#13;
<!DOCTYPE HTML>
<!-- #include virtual="/includeit/dbfunc.asp" -->

<%
	set oConn = server.createobject("ADODB.Connection")
	set oRS = server.createobject("ADODB.Recordset")
	
	call open_connection
%>

<html>
<head>
<script>
window.onload = function () {

var chart = new CanvasJS.Chart("chartContainer", {
	animationEnabled: true,
	title:{
		text: "Average GPA by Class"
	},
	data: [{
		type: "column",
		indexLabelFontColor: "#5A5757",
		indexLabelPlacement: "outside",
		dataPoints: [
<%
	sSQL = "SELECT AVG (CadetGPAs.WeightedGPA) as AverageGPA" &_
			"FROM CadetGPAs INNER JOIN" &_
			"Cadets ON CadetGPAs.PropertyID = Cadets.PropertyID" &_
			"Where Cadets.Active = 1 and Cadets.CurrentGrade = 7"
			
		oRS.open SSQL, oConn
			response.write("{ label: " & chr(34) & "7" & chr(34) & ", y: " & oRS("AverageGPA") & ", indexLabel: " & chr(34) & oRS("AverageGPA") & chr(34) & " }, " & vbcrlf)
		oRS.close
		
	sSQL = "SELECT AVG (CadetGPAs.WeightedGPA) as AverageGPA" &_
			"FROM CadetGPAs INNER JOIN" &_
			"Cadets ON CadetGPAs.PropertyID = Cadets.PropertyID" &_
			"Where Cadets.Active = 1 and Cadets.CurrentGrade = 8"
			
		oRS.open SSQL, oConn
			response.write("{ label: " & chr(34) & "8" & chr(34) & ", y: " & oRS("AverageGPA") & ", indexLabel: " & chr(34) & oRS("AverageGPA") & chr(34) & " }, " & vbcrlf)
		oRS.close
		
	sSQL = "SELECT AVG (CadetGPAs.WeightedGPA) as AverageGPA" &_
			"FROM CadetGPAs INNER JOIN" &_
			"Cadets ON CadetGPAs.PropertyID = Cadets.PropertyID" &_
			"Where Cadets.Active = 1 and Cadets.CurrentGrade = 9"
			
		oRS.open SSQL, oConn
			response.write("{ label: " & chr(34) & "9" & chr(34) & ", y: " & oRS("AverageGPA") & ", indexLabel: " & chr(34) & oRS("AverageGPA") & chr(34) & " }, " & vbcrlf)
		oRS.close
		
	sSQL = "SELECT AVG (CadetGPAs.WeightedGPA) as AverageGPA" &_
			"FROM CadetGPAs INNER JOIN" &_
			"Cadets ON CadetGPAs.PropertyID = Cadets.PropertyID" &_
			"Where Cadets.Active = 1 and Cadets.CurrentGrade = 10"
			
		oRS.open SSQL, oConn
			response.write("{ label: " & chr(34) & "10" & chr(34) & ", y: " & oRS("AverageGPA") & ", indexLabel: " & chr(34) & oRS("AverageGPA") & chr(34) & " }, " & vbcrlf)
		oRS.close
		
	sSQL = "SELECT AVG (CadetGPAs.WeightedGPA) as AverageGPA" &_
			"FROM CadetGPAs INNER JOIN" &_
			"Cadets ON CadetGPAs.PropertyID = Cadets.PropertyID" &_
			"Where Cadets.Active = 1 and Cadets.CurrentGrade = 11"
			
		oRS.open SSQL, oConn
			response.write("{ label: " & chr(34) & "11" & chr(34) & ", y: " & oRS("AverageGPA") & ", indexLabel: " & chr(34) & oRS("AverageGPA") & chr(34) & " }, " & vbcrlf)
		oRS.close
		
	sSQL = "SELECT AVG (CadetGPAs.WeightedGPA) as AverageGPA" &_
			"FROM CadetGPAs INNER JOIN" &_
			"Cadets ON CadetGPAs.PropertyID = Cadets.PropertyID" &_
			"Where Cadets.Active = 1 and Cadets.CurrentGrade >= 12"
			
		oRS.open SSQL, oConn
			response.write("{ label: " & chr(34) & "12" & chr(34) & ", y: " & oRS("AverageGPA") & ", indexLabel: " & chr(34) & oRS("AverageGPA") & chr(34) & " }, " & vbcrlf)
		oRS.close
		
		oConn.close
			set oRS = nothing
			set oConn = nothing
%>

		]
	}]
});
chart.render();

}
</script>
<script type="text/javascript" src="/inc/canvasjs.min.js"></script>
</head>
<body>
	<p align=center>
	<div id="chartContainer" style="height: 98%; width: 98%;">
	</div>
</body>
</html>
&#13;
&#13;
&#13;

这段代码甚至不会绘制图形,我无法弄清楚生活中发生了什么。

它返回的源代码是

&#13;
&#13;
<!DOCTYPE HTML>


<html>
<head>
<script>
window.onload = function () {

var chart = new CanvasJS.Chart("chartContainer", {
	animationEnabled: true,
	title:{
		text: "Average GPA by Class"
	},
	data: [{
		type: "column",
		indexLabelFontColor: "#5A5757",
		indexLabelPlacement: "outside",
		dataPoints: [
 <font face="Arial" size=2>
<p>Microsoft OLE DB Provider for ODBC Drivers</font> <font face="Arial" size=2>error '80040e14'</font>
<p>
<font face="Arial" size=2>[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'CadetGPAs'.</font>
<p>
<font face="Arial" size=2>/Grice/AVGPA.asp</font><font face="Arial" size=2>, line 32</font> 
&#13;
&#13;
&#13;

但Datapoints部分应该更像

&#13;
&#13;
data: [{
		type: "column",
		indexLabelFontColor: "#5A5757",
		indexLabelPlacement: "outside",
		dataPoints: [
			{ label : "7", y: 3, indexLabel: "3" },
			{ label : "8", y: 2.7, indexLabel: "2.7" },
			{ label : "9", y: 4, indexLabel: "4" },
			{ label : "10", y: 2, indexLabel: "2" },
			{ label : "11", y: 1.5, indexLabel: "1.5" },
			{ label : "12", y: 4.3, indexLabel: "4.3" }
&#13;
&#13;
&#13; ASP中的某个地方没有输出数据点

的信息

0 个答案:

没有答案