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. General Programming
  3. C#
  4. Build query using strings ?

Build query using strings ?

Scheduled Pinned Locked Moved C#
databasequestion
9 Posts 4 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.
  • S Offline
    S Offline
    spankyleo123
    wrote on last edited by
    #1

    Hi all , I want to pass the table name as parameter to the method to obtain the result. The code is as follows:- private static String GetText(int id , String tableName) { tbTest myTest = new tbTest(); // I want to create this dynamically using the table name provided in the parameter ? myTest = dataContext.tbTests.Single(table => table.Test_id == id); return myTest.Test_Text; } Is there anyway where-in I can pass the id and table name to obtain the corresponding text (probably by strings ??) ? I hope it makes sense. thanks,

    P D R 3 Replies Last reply
    0
    • S spankyleo123

      Hi all , I want to pass the table name as parameter to the method to obtain the result. The code is as follows:- private static String GetText(int id , String tableName) { tbTest myTest = new tbTest(); // I want to create this dynamically using the table name provided in the parameter ? myTest = dataContext.tbTests.Single(table => table.Test_id == id); return myTest.Test_Text; } Is there anyway where-in I can pass the id and table name to obtain the corresponding text (probably by strings ??) ? I hope it makes sense. thanks,

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      What? Is this a database question? We need more information.

      S 1 Reply Last reply
      0
      • S spankyleo123

        Hi all , I want to pass the table name as parameter to the method to obtain the result. The code is as follows:- private static String GetText(int id , String tableName) { tbTest myTest = new tbTest(); // I want to create this dynamically using the table name provided in the parameter ? myTest = dataContext.tbTests.Single(table => table.Test_id == id); return myTest.Test_Text; } Is there anyway where-in I can pass the id and table name to obtain the corresponding text (probably by strings ??) ? I hope it makes sense. thanks,

        D Offline
        D Offline
        dan sh
        wrote on last edited by
        #3

        If you mean that the parameter tableName will be the name of class whose object you need to create, you can make use of reflection.

        S 1 Reply Last reply
        0
        • S spankyleo123

          Hi all , I want to pass the table name as parameter to the method to obtain the result. The code is as follows:- private static String GetText(int id , String tableName) { tbTest myTest = new tbTest(); // I want to create this dynamically using the table name provided in the parameter ? myTest = dataContext.tbTests.Single(table => table.Test_id == id); return myTest.Test_Text; } Is there anyway where-in I can pass the id and table name to obtain the corresponding text (probably by strings ??) ? I hope it makes sense. thanks,

          R Offline
          R Offline
          Ravi Bhavnani
          wrote on last edited by
          #4

          dataContext.GetTable()[^] perhaps? /ravi

          My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

          1 Reply Last reply
          0
          • P PIEBALDconsult

            What? Is this a database question? We need more information.

            S Offline
            S Offline
            spankyleo123
            wrote on last edited by
            #5

            I want to create and execute a dynamic query in the method by passing in the table name and ID. I hope it makes sense.?

            P 1 Reply Last reply
            0
            • D dan sh

              If you mean that the parameter tableName will be the name of class whose object you need to create, you can make use of reflection.

              S Offline
              S Offline
              spankyleo123
              wrote on last edited by
              #6

              Reflection? I havnt used that before...can u elaborate on it plz. Thanks

              1 Reply Last reply
              0
              • S spankyleo123

                I want to create and execute a dynamic query in the method by passing in the table name and ID. I hope it makes sense.?

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #7

                It makes sense, but it isn't enough information.

                S 1 Reply Last reply
                0
                • P PIEBALDconsult

                  It makes sense, but it isn't enough information.

                  S Offline
                  S Offline
                  spankyleo123
                  wrote on last edited by
                  #8

                  Please let me know wat info do u require? private static String GetText(int id , String tableName) { // I want to pass the name of table as String to dynamically initialize the actual table here // for example if I pass the table name as "tbName" i would like to create something like this // tbName myName = new tbName(); // and then the next line as myName = dataContext.tbNames.Single(table => table.Name_id == id) // and finally return myName.Name_Text as output. tbTest myTest = new tbTest(); // I want to create this dynamically using the table name provided in the parameter ? myTest = dataContext.tbTests.Single(table => table.Test_id == id); return myTest.Test_Text; } I want the code to return the appropriate Text depending on the parameters passed ie tableName and ID

                  P 1 Reply Last reply
                  0
                  • S spankyleo123

                    Please let me know wat info do u require? private static String GetText(int id , String tableName) { // I want to pass the name of table as String to dynamically initialize the actual table here // for example if I pass the table name as "tbName" i would like to create something like this // tbName myName = new tbName(); // and then the next line as myName = dataContext.tbNames.Single(table => table.Name_id == id) // and finally return myName.Name_Text as output. tbTest myTest = new tbTest(); // I want to create this dynamically using the table name provided in the parameter ? myTest = dataContext.tbTests.Single(table => table.Test_id == id); return myTest.Test_Text; } I want the code to return the appropriate Text depending on the parameters passed ie tableName and ID

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #9

                    What you've presented is gibberish to me. I want to know what you are trying to accomplish, not how you are trying to accomplish it (especially if it doesn't work). 0) Is there a database? 1) Is there a table in the database? 2) Are you trying to retrieve some information from that database table? 3) What is the schema of the table?

                    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