title: Dynamically taking a table name in aspx form using sql server
body: <p>I'm trying to dynamically accept a table name depending on the conditions satisfied, also the column name is selected dynamically, and so is the comparison value, but I'm getting an error while running it.  I'm writing this code in C# and my backend is SQL server 2005.  Please help me.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>
     if( table=="studenttab")
  
                     table = "personal_detail";
  
                 thisconnection1.Open();
  
                 string p = field[0].ToString().ToLower();
  
                 string q = code[0].ToString();
  
             SqlCommand thiscommand3 = thisconnection1.CreateCommand();
  
             thiscommand3.CommandText = " Select * from '" + table + "' where '" + p + "' = '" + q + "' ";
  
             // here it gives error "Incorrect syntax near 'personal_detail'." Dont understand!
  
             SqlDataReader thisreader3 = thiscommand3.ExecuteReader();
  
  </code></pre>