change the table name during runtime

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeevan shetty
    New Member
    • Mar 2012
    • 1

    change the table name during runtime

    my question is that i have to change the table name during runtime. depending on the items selected in the dropdownlist.
    i am using asp.net as front end, c# as code behind language, and sql server 2005 as back end.
    " i need to change table name in the query in the aspx.cs page"

    can i???
  • Gopi
    New Member
    • Mar 2012
    • 5

    #2
    Hi jeevan shetty

    i cant understand ur problem but you can change the tablename or colum name while we select using alias concept
    ex: Select columnname as changecolumname from tablename as changetablename
    it give result as changecolumname and changetablename

    it is not enough to solve ur problem means
    can you post ur code where problem arrives

    Comment

    • debasisdas
      Recognized Expert Expert
      • Dec 2006
      • 8119

      #3
      You need to frame the SQL dynamically at run time and pass the table name as an parameter.

      Comment

      • nbiswas
        New Member
        • May 2009
        • 149

        #4
        Though too late in answering but still ...Since you are writing in Asp.net .cs file, try with

        Code:
        string tblName = "someTblName";
        string str = string.Format("Select * From {0} ", tblName);
        Hope this will help

        Comment

        • adaagu05
          New Member
          • Aug 2012
          • 3

          #5
          hi you can use the table name in the query.
          create a string: strtable as string

          recordset like: rs1 as recordset

          strtable =put the name of the table here dynamically

          rs1.open "select * from " & strtable & " where .....;"

          try this and let you and i be friends and work together.

          my name is dan on <email removed per forum policy>
          Last edited by Rabbit; Aug 30 '12, 08:42 PM. Reason: email removed per forum policy

          Comment

          Working...