Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Help with parameters

Help with parameters

Scheduled Pinned Locked Moved Database
databasehelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi I'm using this code:

    cmd = new MySqlCommand("SELECT * FROM @table ORDER BY size LIMIT 20", conn);
    cmd.Parameters.Add("@table", table);
    reader = cmd.ExecuteReader();

    However, @table is not replaced with the variable table, and thus I get an exception that my SQL query is not correct. Can someone tell me what I'm doing wrong? regards

    R 1 Reply Last reply
    0
    • L Lost User

      Hi I'm using this code:

      cmd = new MySqlCommand("SELECT * FROM @table ORDER BY size LIMIT 20", conn);
      cmd.Parameters.Add("@table", table);
      reader = cmd.ExecuteReader();

      However, @table is not replaced with the variable table, and thus I get an exception that my SQL query is not correct. Can someone tell me what I'm doing wrong? regards

      R Offline
      R Offline
      rujuc
      wrote on last edited by
      #2

      You can solve your problem by taking help from this link http://www.nigelrivett.net/SQLTsql/TableNameAsVariable.html[^] cheers!! :)

      L 1 Reply Last reply
      0
      • R rujuc

        You can solve your problem by taking help from this link http://www.nigelrivett.net/SQLTsql/TableNameAsVariable.html[^] cheers!! :)

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Thanks :) Do I really need stored procedures for this task? I actually just wanted to avoid SQL injections, something like mysql_escape_string(table) does in PHP. regards

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups