madfrog
01-06-2005, 09:00 AM
Hi all, got SQL syntex error during asp coding...
i define a variable named "talbeName" and assign it value thru form submit...then combine this variable with another string to form an SQL string...then send it to database using recordset...below are the code:
-------------------------------------------------------
.......
tableName=request.form("tableName")
SQLStr="select * from "&tableName
set conn=Server.CreateObject("ADODB.Connection")
conn.Open "............."
set rs = Server.CreateObject("ADODB.recordset")
rs.open SQLStr, conn,3,3
.......
-------------------------------------------------------
the error says: [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near 'from'.
my tableName's value is "system_lookup"---this table does exist in database...when i write my code as SQLStr="select * from system_lookup", everything works fine.
So wat's wrong with my coding:SQLStr="select * from "&tableName?
i define a variable named "talbeName" and assign it value thru form submit...then combine this variable with another string to form an SQL string...then send it to database using recordset...below are the code:
-------------------------------------------------------
.......
tableName=request.form("tableName")
SQLStr="select * from "&tableName
set conn=Server.CreateObject("ADODB.Connection")
conn.Open "............."
set rs = Server.CreateObject("ADODB.recordset")
rs.open SQLStr, conn,3,3
.......
-------------------------------------------------------
the error says: [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near 'from'.
my tableName's value is "system_lookup"---this table does exist in database...when i write my code as SQLStr="select * from system_lookup", everything works fine.
So wat's wrong with my coding:SQLStr="select * from "&tableName?