title: I receive the following error 'Data type mismatch in criteria expression' when adding data
body: <p>I have the following error but I am not sure why I am getting this error. When I attempt to add data to the database I receive this error. </p>
  
  <p><strong>Data type mismatch in criteria expression.</strong></p>
  
  <p>The code I am working on is below. Can anyone please help? Thanks </p>
  
  <pre><code> Private Sub RefreshData()
      If Not cnn.State = ConnectionState.Open Then
          'open connection
          cnn.Open()
      End If
  
      Dim da As New OleDb.OleDbDataAdapter("SELECT Item ID as [Item ID], " &amp; _
                                           "Item Name as [Item Name], " &amp; _
                                           "Item Type as [Item Type], " &amp; _
                                           "Quantity as [Quantity], " &amp; _
                                           "Min Shelf Stock as [Min Shelf Stock], " &amp; _
                                           "Purchase Price as [Purchase Price], Note " &amp; _
                                           " From Product ORDER BY Item ID", cnn)
      Dim dt As New DataTable
      'fill data to datatable 
      da.Fill(dt)
  
      'offer data in data table into datagridview
      Me.dgvData.DataSource = dt
  
      'Close the connection
      cnn.Close()
  End Sub
  
  Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
          Dim cmd As New OleDb.OleDbCommand
          If Not cnn.State = ConnectionState.Open Then
              'The line of code below opens the connection to the database if it isnt open
          cnn.Open()
          End If
  
      cmd.Connection = cnn
      'Check whether to add new or update
      If Me.txtItemID.Tag &amp; "" = "" Then
          'Add new 
          'The line of coding below adds data to table
          cmd.CommandText = "INSERT INTO Product ([Item Id], [Item Name], [Item Type], [Quantity], [Min Shelf Stock], [Purchase Price], [Note]) VALUES (@id, @name, @iType, @quantity, @minshelfstock, @price, @note)"
          cmd.Parameters.AddWithValue("@id", txtItemID.Text)
          cmd.Parameters.AddWithValue("@name", txtItemName.Text)
          cmd.Parameters.AddWithValue("@iType", cboItemType.Text)
          cmd.Parameters.AddWithValue("@quantity", txtQuantity.Text)
          cmd.Parameters.AddWithValue("@minshelfstock", txtMinShelfStock.Text)
          cmd.Parameters.AddWithValue("@price", txtPurchasePrice.Text)
          cmd.Parameters.AddWithValue("@note", txtNote.Text)
          cmd.ExecuteNonQuery()
      Else
          'Update data in the table 
          cmd.CommandText = "UPDATE Product " &amp; _
                      " SET [Item ID]=" &amp; Me.txtItemID.Text &amp; _
                      ", [Item Name]='" &amp; Me.txtItemName.Text &amp; "'" &amp; _
                      ", [Item Type]='" &amp; Me.cboItemType.Text &amp; "'" &amp; _
                      ", [Quantity]=" &amp; Me.txtQuantity.Text &amp; "" &amp; _
                      ", [Min Shelf Stock]=" &amp; Me.txtMinShelfStock.Text &amp; "" &amp; _
                      ", [Purchase Price]=" &amp; Me.txtPurchasePrice.Text &amp; "" &amp; _
                      ", [Note]='" &amp; Me.txtNote.Text &amp; "'" &amp; _
                      " WHERE [Item ID]=" &amp; Me.txtItemID.Tag
          cmd.ExecuteNonQuery()
      End If
      'Refresh data in list
      RefreshData()
      'Clear the form
      Me.btnClear.PerformClick()
  
      'The code below closes the connection to the database
      cnn.Close()
  End Sub
  
  Private Sub Product_Load(sender As Object, e As EventArgs) Handles Me.Load
      cnn = New OleDb.OleDbConnection
      cnn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" &amp; Application.StartupPath &amp; "\inventorysystem.mdb"
      '
      'Get the data into a list
      Me.RefreshData()
  End Sub
  
  Private Sub btnEdit_Click(sender As Object, e As EventArgs) Handles btnEdit.Click
      'check for the selected item in list
      If Me.dgvData.Rows.Count &gt; 0 Then
          If Me.dgvData.SelectedRows.Count &gt; 0 Then
              Dim intItemID As Integer = Me.dgvData.SelectedRows(0).Cells("Item ID").Value
              'Get the data from database followed Item ID
              'Open the connection
              If Not cnn.State = ConnectionState.Open Then
                  cnn.Open()
              End If
              'Get the data into the datatable
              Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM Product " &amp; _
                                                    " WHERE Item ID=" &amp; intItemID, cnn)
              Dim dt As New DataTable
              da.Fill(dt)
  
              Me.txtItemID.Text = intItemID
              Me.txtItemName.Text = dt.Rows(0).Item("Item Name")
              Me.cboItemType.Text = dt.Rows(0).Item("Item Type")
              Me.txtQuantity.Text = dt.Rows(0).Item("Quantity")
              Me.txtMinShelfStock.Text = dt.Rows(0).Item("Min Shelf Stock")
              Me.txtPurchasePrice.Text = dt.Rows(0).Item("Purchase Price")
              Me.txtNote.Text = dt.Rows(0).Item("Note")
              '
              'Hide the ID to be edited in TAG od txtItemID in case ID is changed 
              Me.txtItemID.Tag = intItemID
              'Change the add button to update 
              Me.btnAdd.Text = "Update"
              'Disable the Edit button
              Me.btnEdit.Enabled = False
              'Close the connection
              cnn.Close()
          End If
      End If
  End Sub
  
  Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
      'Check for the selected item in the list
      If Me.dgvData.Rows.Count &gt; 0 Then
          If Me.dgvData.SelectedRows.Count &gt; 0 Then
              Dim intItemID As Integer = Me.dgvData.SelectedRows(0).Cells("Item ID").Value
              'Open the connection 
              If Not cnn.State = ConnectionState.Open Then
                  cnn.Open()
              End If
  
              'Delete data 
              Dim cmd As New OleDb.OleDbCommand
              cmd.Connection = cnn
              cmd.CommandText = "DELETE FROM Product WHERE Item ID" &amp; intItemID
              cmd.ExecuteNonQuery()
              'Refresh the data 
              Me.RefreshData()
  
              'Close the connection
              cnn.Close()
          End If
      End If
  End Sub
  </code></pre>
  
  <p>End Class</p>