Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert variable inside a Select statement

Tags:

c#

string table = "City";
string query = "Select * from '"+table+"'";

This gives me error stating incorrect symbol near ".

However,

string query = "Select * from City";

Gives the proper output.

like image 580
subhro Avatar asked Nov 24 '15 05:11

subhro


1 Answers

You just this

string query = "Select * from '"+table+"'";

to be replaced by

string query = "Select * from " + table;

Because you Query string is not "Select * from City"; While it is forming "Select * from 'City'";

and thus you getting error

like image 76
Mohit S Avatar answered Oct 02 '22 00:10

Mohit S