You can put (and in !) Parameters in your SQL queries for values, for example. your WHERE , but you cannot parameterize the material, for example, the name of your table.
So, I would rewrite this query:
SELECT (list of columns) FROM dbo.Actor WHERE ActorName = @ActorName
and then enter only the value for @ActorName .
If you need to do the same for directors, you will have to have a second request
SELECT (list of columns) FROM dbo.Directors WHERE DirectorName = @DirectorName
Using options like
- increases security (prohibits SQL injection attacks!)
- improves performance: the query plan for this request can be cached and reused for the second, third run
PS: the initial problem in your setup is this: you have no place between the first input of your table name and the WHERE - this way you get:
SELECT * FROM ActorWHERE ActorName ='.....'
If you really insist on joining your SQL statement (I would recommend NOT !), Then you need to put a space between the name of your table and your WHERE !
Update: some resources for learning parameterized queries in ADO.NET:
source share