title: How to fix incorrect syntax near '?'
body: <p>When I execute this code, I'm getting an error in the SQL command </p>
  
  <blockquote>
    <p>Incorrect syntax near '?'</p>
  </blockquote>
  
  <p>This is my code:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Dim command As New SqlCommand("SELECT [username], [password] FROM [stud_table] WHERE [username] = ?", connection)
  command.Parameters.AddWithValue("username", Me.UsernameTextBox.Text)
  
  Try
      connection.Open()
  
      Dim adapter As New SqlDataAdapter(command)
  
      Dim rec As SqlDataReader = command.ExecuteScalar()
  
      If rec.HasRows Then
          rec.Read()
  
          If Me.PasswordTextBox.Text.ToLower = rec.Item("password").ToString Then
              MsgBox("Login successful")
              Me.Hide()
              user_profile.Show()
          Else
              MsgBox("Login unsuccessful, Incorrect Password", MsgBoxStyle.OkOnly, "Invalid")
          End If
      Else
          MsgBox("Login unsuccessful, Invalid UserName", MsgBoxStyle.OkOnly, "Invalid")
      End If
      rec.Close()
  Catch ex As OleDb.OleDbException
      MsgBox("Login unsuccessful,no connection", MsgBoxStyle.OkOnly, "Invalid")
  Catch ex As Exception
      MessageBox.Show(ex.Message)
  Finally
      connection.Close()
  End Try
  </code></pre>