Change source at runtime
-
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
-
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
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 heresqlConnection.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)