...

View Full Version : About ASP SQL problem



madfrog
01-06-2005, 10: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?

glenngv
01-06-2005, 10:57 AM
When you response.write SQLStr, is the output the same as what you expect it to be?

madfrog
01-07-2005, 02:38 AM
When you response.write SQLStr, is the output the same as what you expect it to be?

YES it is

ghell
01-07-2005, 04:09 PM
the qs table definately exists?

try conn.execute(SQLstr)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum