Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Nov 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    About ASP SQL problem

    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?

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    When you response.write SQLStr, is the output the same as what you expect it to be?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New to the CF scene
    Join Date
    Nov 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv
    When you response.write SQLStr, is the output the same as what you expect it to be?
    YES it is

  • #4
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    the qs table definately exists?

    try conn.execute(SQLstr)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •