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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -