c# - Can we use variable for a table name in query? -


here in code trying retrieve information database , store in table. in query have used variable specify table, doing because want use single piece of code retrieve information various tables based on table name variable "a" contain when executing it's throwing me exception. please help...

myoledbconnection.open(); string = "login"; string query = string.format("select email,username,phoneno,department '{1}' email='{0}'", editrecordtextbox.text,a); datatable dt = new datatable(); oledbdataadapter da = new oledbdataadapter(); da = new oledbdataadapter(query, myoledbconnection.vcon); da.fill(dt); 

note- part of code, exception occuring in code only.

your code in fact working correctly.

first of all, remove single quotes around table name. these mark text, not identifier or name.

i can imagine login reseverd name cannot use plain text in sql. depending on database can quote tablename recognizes name, not reserved word.

for sql-server done [ , ]:

string query = string.format("select email,username,phoneno,department [{1}] email='{0}'", editrecordtextbox.text,a); 

if give database, help.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -