3 Replies - 897 Views - Last Post: 07 October 2012 - 03:38 PM Rate Topic: -----

#1 AngelaFey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 06-October 12

Data type mismatch in criteria expression

Posted 06 October 2012 - 11:15 PM

I am trying to add a new record on my data grid view table but an error always occur saying "Data type mismatch in criteria expression" and "OleDB Exception was unhandled" what was wrong? what was wrong with the code?


Imports System.Data.OleDb
Public Class frmMain

    Dim myconnection As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\order\Order\Order\Orders.accdb")

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sql As String
        myconnection.Open()

        sql = " Select * from Orders"

        Dim da As New OleDb.OleDbDataAdapter(sql, myconnection)
        Dim dt As New DataTable("tblOrder")

        da.Fill(dt)
        dgv1.DataSource = dt.DefaultView
        RefreshDGV()

        myconnection.Close()


    End Sub


    Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
        Dim sqlsearch As String
        sqlsearch = "SELECT * FROM Orders WHERE ID LIKE '%" & txtSearch.Text & "%'" & " OR Description LIKE '%" & txtSearch.Text & "%'"

        Dim da As New OleDbDataAdapter(sqlsearch, myconnection)
        Dim dt As New DataTable("Orders")
        da.Fill(dt)
        dgv1.DataSource = dt.DefaultView


    End Sub

    Private Sub cboSearch_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboSearch.SelectedIndexChanged
        

        If Not cboSearch.Text = cboSearch.SelectedText Then
            btnSave.Enabled = True
        End If


        Dim MyVariable As String

        MyVariable = cboSearch.Text

        MsgBox(MyVariable)

    End Sub

    Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles btnAdd.Click
        frmAdd.Show()
    End Sub

    Private Sub RefreshDGV()

    End Sub

    Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click

      
       
    End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Data type mismatch in criteria expression

#2 AngelaFey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 06-October 12

Re: Data type mismatch in criteria expression

Posted 06 October 2012 - 11:53 PM

here's the file -- so that you will have a hard time understanding me :)) Thanks!Attached File  Order.zip (184.71K)
Number of downloads: 34

here's the file -- so that you will NOT have a hard time understanding me :) Thanks!Attached File  Order.zip (184.71K)
Number of downloads: 20
Was This Post Helpful? 0
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1533
  • View blog
  • Posts: 4,919
  • Joined: 25-September 09

Re: Data type mismatch in criteria expression

Posted 07 October 2012 - 04:58 AM

If ID is a numeric field, you don't wrap it with apostrophes like you do a text field.

In your INSERT code as I was going to point out yesterday in your other topic that was closed, you are trying to insert a null value into an AutoNumber field. Remove ID from your insert statement. since it is an AutoNumber field it will generate a new number when a new row is inserted.

This post has been edited by CharlieMay: 07 October 2012 - 05:14 AM

Was This Post Helpful? 0
  • +
  • -

#4 AngelaFey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 06-October 12

Re: Data type mismatch in criteria expression

Posted 07 October 2012 - 03:38 PM

thank you sir!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1