title: SQL Server select query execution from c#
body: <pre><code>string user = "1234";
  string strSQL = string.Format("Select * From User where UserId = '{0}'",user);
  SqlCommand myCommand = new SqlCommand(strSQL, cnn);
  reader = myCommand.ExecuteReader();
  </code></pre>
  
  <p>My <code>User</code> table consists of <code>UserId</code> and <code>Password</code> columns. The <code>UserId</code> column type is <code>nchar</code> and so I've used the single quotes. I get an error saying that </p>
  
  <blockquote>
    <p><em>incorrect syntax near the keyword User"</em></p>
  </blockquote>
  
  <p>(I guess the table name <code>User</code> is being referred to here). </p>
  
  <p>I have the connection string and other database environment related things correctly for I've checked the database connection status and it is open(during program execution).  </p>
  
  <p>What is the error in the syntax? I'm unable to retrieve the rows from my table.</p>