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. LINQ
  4. Change source at runtime

Change source at runtime

Scheduled Pinned Locked Moved LINQ
csharpdatabaselinqquestion
2 Posts 2 Posters 3 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.
  • D Offline
    D Offline
    dbrenth
    wrote on last edited by
    #1

    Is there no way to change the source of a table at runtime? I can't even see the property to GET the source at runtime. But the table name will be changing from time to time. I can query another table for the new table name, but I need to be able to set this as the source to the LINQ table so I can query it using LINQ. Any ideas? Thanks

    H 1 Reply Last reply
    0
    • D dbrenth

      Is there no way to change the source of a table at runtime? I can't even see the property to GET the source at runtime. But the table name will be changing from time to time. I can query another table for the new table name, but I need to be able to set this as the source to the LINQ table so I can query it using LINQ. Any ideas? Thanks

      H Offline
      H Offline
      Harvey Saayman
      wrote on last edited by
      #2

      dbrenth wrote:

      source of a table at runtime

      You can alter the app.config file if you mean you want to change the database the table is located on. And then you can specify the connection string when you create an instance of your data context class.

      dbrenth wrote:

      the table name will be changing from time to time.

      dbrenth wrote:

      I can query another table for the new table name

      This might be harder but not impossible, if this is for use on a public network you cant really do what im about to sugest because it opens up the posibility of SQL injection attacks.

      DO NOT do this if the data is sensitive and/or connected to a network with an
      internet connection! This is meant as something to get you to think towards a better idea, not
      for implementation

      string tableToQuery = "?"; //you can query your table name here

      sqlConnection.Open();
      SqlCommand cmd = sqlConnection.CreateCommand();
      cmd.CommandText = "SELECT columnName From " + tableToQuery + "WHERE someField = someCondition";
      cmd.ExectuteNonQuery(); // or you can use SqlDataReader reader = cmd.ExecuteReader();

      Hope this helps

      Harvey Saayman - South Africa Junior Developer .Net, C#, SQL

      you.suck = (you.passion != Programming)

      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