Solved

SQL recordset syntax problem

Posted on 2004-04-26
6
487 Views
Last Modified: 2012-05-04
Hello guys,

I am trying to setup a dynamic menu that gets columns from the db "sections" table and rows from the "pages" table.

I get the following Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[MySQL][ODBC 3.51 Driver][mysqld-4.0.18-nt]You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''SELECT * FROM tblPages WHERE SectionID=' & 'rsSections(0)'' at dynmenutest.asp, line 30

There seems to be a problem on the SQL syntax of the rsPages recordset.

Here's the code of my page:

<%
Dim Dbq, Dsn, Dc
Dim sSectionName, sPage, sLink
Dim rsSections
Dim rsSections_numRows

Set rsSections = Server.CreateObject("ADODB.Recordset")
rsSections.ActiveConnection = MM_City_conn_STRING
rsSections.Source = "SELECT * FROM city.sections"
rsSections.CursorType = 0
rsSections.CursorLocation = 2
rsSections.LockType = 1
rsSections.Open()

rsSections_numRows = 0
%>
<%
Dim rsPages
Dim rsPages_numRows

Set rsPages = Server.CreateObject("ADODB.Recordset")
rsPages.ActiveConnection = MM_City_conn_STRING
rsPages.Source = "'SELECT * FROM tblPages WHERE SectionID=' & 'rsSections(0)'"
rsPages.CursorType = 0
rsPages.CursorLocation = 2
rsPages.LockType = 1
rsPages.Open()

rsPages_numRows = 0
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript" language="JavaScript1.2" src="stm31.js"></script>
</head>

<body>
<p>
  <script id="Sothink Widgets:dynmenutest.pgt" type="text/javascript" language="JavaScript1.2">
<!--
stm_bm(["menu1b7a",400,"","blank.gif",0,"","",0,0,250,0,1000,1,0,0,"","",0],this);
stm_bp("p0",[1,4,0,0,2,3,0,7,100,"",-2,"",-2,50,0,0,"#fffff7","#fffff7","",3,1,1,"#000000"]);
<%
While Not rsSections.EOF
sSectionName = rsSections("Section")
%>

stm_ai("p0i0",[1,"<%=sSectionName%>","","",-1,-1,0,"","_self","","","","",0,0,0,"arrow_r.gif","arrow_r.gif",7,7,0,0,1,"#fffff7",0,"#b5bed6",0,"","",3,3,1,1,"#fffff7","#000000","#000000","#000000","8pt Verdana","8pt Verdana",0,0]);
stm_bpx("p1","p0",[1,2,0,0,2,3,0,0]);
<%
While Not rsPages.EOF
sPage = rsPages("PageMenuName")
sLink = rsPages("pn")
%>

stm_ai("p1i0",[1,"<%=sPage%>","","",-1,-1,0,"<%=sLink%>","_self","","","","",0,0,0,"","",0,0,0,0,1,"#fffff7",0,"#b5bed6",0,"","",3,3,1,1,"#fffff7","#000000","#000000","#000000","8pt Verdana","8pt Verdana",0,0]);
<%
rsPages.MoveNext
Wend
%>

stm_ep();
<%rsSections.MoveNext%>
<%Wend%>
stm_ep();
stm_em();
//-->
</script>


0
Comment
Question by:matsos
  • 3
  • 2
6 Comments
 
LVL 19

Expert Comment

by:dakyd
ID: 10920703
it looks like you're not concatenating the strings properly for your query

change this line:
rsPages.Source = "'SELECT * FROM tblPages WHERE SectionID=' & 'rsSections(0)'"
to:
rsPages.Source = "SELECT * FROM tblPages WHERE SectionID = " & rsSections(0)

Hope that helps.
0
 

Author Comment

by:matsos
ID: 10920810
Thanks dakyd for your comment.

Although it seems that your syntax is correct, it returned the same error again with one difference. It returned the first value of the recordset.

Here it is:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[MySQL][ODBC 3.51 Driver][mysqld-4.0.18-nt]You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'City College' at line 1
0
 
LVL 7

Accepted Solution

by:
minnirok earned 500 total points
ID: 10921455
You need to enclose the field value in single quotes for the SQL query.  So change it to:

rsPages.Source = "SELECT * FROM tblPages WHERE SectionID = '" & rsSections(0) & "';"

should work.  Note that there are single quotes (') now within your query.  Without these, SQL won't understand that 'City College' is a value (rather than a field or command).
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 19

Expert Comment

by:dakyd
ID: 10921661
minnirok is right, any strings need to wrapped with single quotes or SQL won't realize they are values.  I had assumed that SectionID was an integer, so I left them off.  Hopefully you have what you want now.
0
 

Author Comment

by:matsos
ID: 10921737
Thanks for all your replies guys. The page worked fine, no errors, but there still seems to be a problem as the recordset rsPages did not return any values. :-(

Section_ID is an integer though.
0
 

Author Comment

by:matsos
ID: 10921881
Ok I figured out what the problem was. The field of the Sections table was not the first field to be retrieved in the Mysql db.
I wish I could give the points to both of you.
Thanks for your help.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Move SQL 2005 Express to Server 2012R2 19 128
MySQL ERROR 1045 (28000) 2 80
Online Forms 6 59
Download OAB 0x8004010f An object cannot be found 12 98
APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question