The most likely reason is that your
does not end with a space - so it will get run together with the "where" to form a new name:
SELECT * FROM myTablewhere campaignid= 1
Try adding a space to your code:
string qry = "select * from " + tableName + "where campaignid= " + campaignid;
string qry = "select * from " + tableName + " where campaignid= " + campaignid;
But it is not a good idea to do that anyway: Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
BTW: It is also poor form to use
SELECT * FROM
- it may return data you don't want or need such as image data. It is much better practice to explicitly list the fields you want, in the order you want them.