Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can put (and <strong>should</strong>!) parameters into your SQL queries for the values in e.g. your <code>WHERE</code> clause - but you <strong>cannot</strong> parametrize stuff like your table name.</p> <p>So I'd rewrite that query to be:</p> <pre><code>SELECT (list of columns) FROM dbo.Actor WHERE ActorName = @ActorName </code></pre> <p>and then pass in just the value for <code>@ActorName</code>.</p> <p>If you need to do the same thing for directors, you'd have to have a second query</p> <pre><code>SELECT (list of columns) FROM dbo.Directors WHERE DirectorName = @DirectorName </code></pre> <p>Using parameters like this </p> <ul> <li>enhances security (prohibits SQL injection attacks!)</li> <li>enhances performance: the query plan for that query can be cached and reused for second, third runs</li> </ul> <p>PS: the original problem in your setup is this: you don't have any space between the first occurence of your table name and the <code>WHERE</code> clause - thus you would get:</p> <pre><code>SELECT * FROM ActorWHERE ActorName ='.....' </code></pre> <p>If you really insist on concatenating together your SQL statement (I would <strong>NOT</strong> recommend it!), then you need to put a space between your table name and your <code>WHERE</code> !</p> <p><strong>Update:</strong> some resources for learning about parametrized queries in ADO.NET:</p> <ul> <li><a href="http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson06.aspx" rel="noreferrer">The C# Station ADO.NET Tutorial / Lesson 06: Adding Parameters to Commands</a></li> <li><a href="http://www.asp.net/data-access/tutorials/using-parameterized-queries-with-the-sqldatasource-cs" rel="noreferrer">Using Parameterized Queries with the SqlDataSource</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload