How can I query on a table given as parameter? I just want to check if a record exists.
Example:
String query = "Select * from " + tableName + "t where t.ID='" + fieldvalue + "'";
Regards
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
SenthilkumarRank #387 · 6.5K reputationPosted Mar 28, 2012, 11:26 PM EDT
You can query like this.
Are you going to use the table is not constant? then
string query = "SELECT * FROM " + tableName + " where ID='" + fieldvalue + "'";
You know the table name
string query = "SELECT * FROM tableName WHERE ID='" + fieldvalue + "'";
If your id column is integer column then
string query = "SELECT * FROM " + tableName + " WHERE ID=" + fieldvalue;
Glenn Sanchez30 reputationPosted Apr 2, 2012, 5:01 PM EDT
Sorry for not being clear here. My exact concern is how/what type of class should I use for casting result for dynamic query with LINQ. This is what I mean:
String query = "Select * from " + tableName + "t (nolock) where t.ID='" + fieldvalue + "'";
var res = context.ExecuteQuery<ClassName>(query).ToList();
What should I use as class.
Ajay Patel148 reputationPosted May 31, 2012, 11:22 PM EDT
String query = "Select * from " + tableName + "t where t.ID='" + fieldvalue + "'"; IEnumerableCustomer> results = db.ExecuteQueryCustomer>(query); Class is your entity Class for returned result storeGohil JayendrasinhRank #490 · 5K reputationPosted Jun 12, 2012, 10:38 PM EDT
http://www.hanselman.com/blog/TheWeeklySourceCode48DynamicQueryableMakesCustomLINQExpressionsEasier.aspx