title: sql query returning whole column of data
body: <p>I have a VB.net program that parses a set of variables into a sub that I use to communicate with an Access Database.
  The query string reads:</p>
  
  <pre><code>SELECT ID FROM cbRooms WHERE @condition
  </code></pre>
  
  <p>@condition is given a value with the code:</p>
  
  <pre><code>.Parameters.AddWithValue("@condition", dbCondition)
  </code></pre>
  
  <p>Where dbCondition is, in this case:</p>
  
  <pre><code>H_Block=True
  </code></pre>
  
  <p>When I run this query within Access directly, I get the expected data back, which is a set of numbers, that have a ticked box in Access</p>
  
  <p>However, when I run that same code in Visual Studio, it just returns the whole column, regardless of whether the tick box is true or not</p>
  
  <p>It's been a while since i've written something in VB, so i'm quite rusty, and therefore the problem is likely a simple oversight on my part</p>
  
  <p>Here is the code for the sql access function:</p>
  
  <pre><code>Public Function sqlSelect(ByVal dbCol As String, ByVal dbTable As String, ByVal dbCondition As String)
  
  
      'Creating the sqlCmd string to sent as an SQL request to the Database
      Dim sqlCmd As String
      'Creating a new connection to the database
      Dim conn As New OleDb.OleDbConnection
  
      'Setting the value for the sqlCmd string, with several "@" parameters
      sqlCmd = "SELECT " &amp; dbCol &amp; " FROM " &amp; [dbTable] &amp; " WHERE @condition;"
      'Running the Connect Sub routine to interact with the database
      Connect(conn)
  
      Using conn
          Using dbEvent As New OleDb.OleDbCommand
              With dbEvent
                  'sets the connection used by the current instance of OleDB usng the conn string
                  .Connection = conn
                  'Sets how the .CommandType is interpreted
                  .CommandType = CommandType.Text
                  'Sets the sqlCmd string that will be sent
                  .CommandText = sqlCmd
                  'Setting the "@" parameters in the sqlCmd string using values parsed into the sub routine
                  .Parameters.AddWithValue("@condition", dbCondition)
              End With
  
              Try
                  'Opening connection to the database
                  conn.Open()
                  'Creating the _sqlRead Reader used to read the data coming from the database
                  Dim sqlReader As OleDb.OleDbDataReader
                  sqlReader = dbEvent.ExecuteReader()
  
                  'Creates a list that will store the values returned to the Search.vb class
                  Dim returnVals As New List(Of Integer)
  
                  Do While sqlReader.Read = True
                      returnVals.Add(sqlReader(dbCol))
                  Loop
  
                  Return returnVals
  
              Catch ex As Exception
                  'Opens a message box showing the current error
                  MessageBox.Show(ex.Message.ToString(), "Error Message")
              End Try
          End Using
      End Using
  End Function
  </code></pre>
  
  <p>And Here is the code for the combo box that calls the AccessSQL.vb:</p>
  
  <pre><code>Public Sub cbBlock_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbBlock.SelectedIndexChanged
      Select Case cbBlock.Text
          Case "H Block"
              cbRoom.Items.Clear()
              Dim listOfRoomsInBlock As New List(Of Integer)
              listOfRoomsInBlock = sqlSelect("ID", "cbRooms", "H_Block=True")
              For x = 0 To listOfRoomsInBlock.Count - 1
                  cbRoom.Items.Add(listOfRoomsInBlock(x))
              Next
          Case "Tech Block"
              cbRoom.Items.Clear()
              Dim listOfRoomsInBlock As New List(Of Integer)
              listOfRoomsInBlock = sqlSelect("ID", "cbRooms", "T_Block=True")
              For x = 0 To listOfRoomsInBlock.Count - 1
                  cbRoom.Items.Add(listOfRoomsInBlock(x))
              Next
  
      End Select
  End Sub
  </code></pre>
  
  <p>Thanks for any help!</p>
  
  <p>EDIT:
  The SQL, when run in VB returns <a href="https://i.stack.imgur.com/yWuL9.jpg" rel="nofollow noreferrer">This</a> into the combo box I'm trying to populate
  The 1 - 13 values at the bottom is what I'm expecting, whereas the 14 - 30 is not. My thinking is that my parameterisation is never actually using the condition I set above.</p>
  
  <p>However, when I run that same, <a href="https://i.stack.imgur.com/37n1T.png" rel="nofollow noreferrer">expected query</a>, inside Access, I get the right <a href="https://i.stack.imgur.com/fOKVS.png" rel="nofollow noreferrer">values returned</a></p>