Error while parsing parametrized query C# -
this question has answer here:
- parameterise table name in .net/sql? 7 answers
i keep getting error while trying parse parametrized query. error: token in error = @tablename
seems ok variables, tried passing strings still same.
using (sqlcecommand command = new sqlcecommand("select * @tablename @columnname = @id", connection)) { command.parameters.add(new sqlceparameter("tablename", tablename)); command.parameters.add(new sqlceparameter("columnname", column)); command.parameters.add(new sqlceparameter("id", id));
edit1:
yes might wrong way of querying database. example if need access different tables @ different time of runtime whats suitable way of doing it. mean architecture of class accesses database.
i trying use access 2 tables @ different runtime. pass these 3 variables , return output.
p.s apologise if im breaking rules.
edit2:
sorry if didnt make clear theres question.
what architecture(if can call that) better accessing different database tables @ different time while running application? mean solution that? or bad , on.
you cannot put parameters on table names , columns. seeing using sql compact edition. can set command in c# this:
sqlcommand.commandtext = "select * " + yourtablename + " " + yourcolumnname+" @param"; sqlcommand.parameters.add("@param", sqldbtype.nvarchar).value = paramval + "%";
fyi, should aware code open sql injection.
Comments
Post a Comment