title: SQL Data type mismatch in criteria expression
body: <p>When running the expression below I get an error saying:</p>
  
  <pre><code> Data type mismatch in criteria expression
  </code></pre>
  
  <p>The message boxes are used to identify where error happened, it gets to checkpoint 1 then it stops!</p>
  
  <pre><code>                    Dim table2 As New DataTable
                      Dim recordcount2 As Integer
                      Dim command2 As String = "SELECT * FROM [Results] where " &amp; "[TestID] = " &amp; " '" &amp; CInt(LocationID) &amp; "'"
                      Dim adapter2 As New OleDb.OleDbDataAdapter(command2, conn)
                      table2.Clear()
                      MsgBox("Checkpoint 1")
                      recordcount2 = adapter2.Fill(table2)
                      MsgBox("Checkpoint 2")
  </code></pre>
  
  <p>The code is in this section of my program:</p>
  
  <pre><code>    Try
          'Defining variables
          Dim table As New DataTable
          Dim command As String
          Dim recordCount As Integer
          Dim LocationID As Integer
          command = "SELECT * FROM [Test] where " &amp; "[MachineID] = " &amp; " '" &amp; machineID &amp; "'" 'SQL command to find if there is a usename stored with that is in username text box
  
          Dim adapter As New OleDb.OleDbDataAdapter(command, conn) 'adapter
          table.Clear() 'adding data to a table.
          recordCount = adapter.Fill(table)
          If recordCount &lt;&gt; 0 Then
              For i = 0 To recordCount
                  Try
                      LocationID = CInt(table.Rows(i)(0))
                      Dim table2 As New DataTable
                      Dim recordcount2 As Integer
                      Dim command2 As String = "SELECT * FROM [Results] where " &amp; "[TestID] = " &amp; " '" &amp; CInt(LocationID) &amp; "'"
                      Dim adapter2 As New OleDb.OleDbDataAdapter(command2, conn)
                      table2.Clear()
                      MsgBox("Checkpoint 1")
                      recordcount2 = adapter2.Fill(table2)
                      MsgBox("Checkpoint 2")
                      If recordcount2 &lt;&gt; 0 Then
                          For x = 0 To recordcount2
                              MsgBox("yay1")
                              Dim TestID As String = table2.Rows(x)(1)
                              Dim Thickness As String = table2.Rows(x)(2)
                              Dim TargetFilter As String = table2.Rows(x)(9)
                              Dim SNR As String = table2.Rows(x)(3)
                              Dim STD As String = table2.Rows(x)(4)
                              MsgBox("yay2")
                              Dim M1 As String = table2.Rows(x)(5)
                              Dim M2 As String = table2.Rows(x)(6)
                              Dim kVp As String = table2.Rows(x)(7)
                              Dim mAs As String = table2.Rows(x)(8)
                              MsgBox("yay3")
                              Dim CNR As Short = (CLng(M1) - CLng(M2)) / 2
                              MsgBox("Further")
                              dgvViewData.Rows.Add(TestID, Thickness, CStr(SNR), CStr(STD), CStr(M1), CStr(M2), kVp, mAs, CStr(CNR))
                          Next
                      Else
                          MsgBox("RIP")
                      End If
                  Catch ex As Exception
                      MessageBox.Show(ex.Message)
                  End Try
              Next
          Else
              MsgBox("There data for this machine.")
          End If
      Catch ex As Exception
          MessageBox.Show(ex.Message)
      End Try
  </code></pre>
  
  <p>Code on button</p>
  
  <pre><code>    Try
          Dim table As New DataTable
          Dim command As String
          Dim recordCount As Integer
          Dim TestNum As String = "1"
          command = "SELECT * FROM [Results] where " &amp; "[TestID] = " &amp; " '" &amp; CStr(TestNum) &amp; "'"
          Dim adapter As New OleDb.OleDbDataAdapter(command, conn)
          table.Clear()
          recordCount = adapter.Fill(table)
      Catch ex As Exception
          MessageBox.Show(ex.Message)
      End Try
  </code></pre>