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
Data type mismatch in criteria expression
Page 1 of 13 Replies - 423 Views - Last Post: 07 October 2012 - 03:38 PM
#1
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?
Replies To: Data type mismatch in criteria expression
#2
Re: Data type mismatch in criteria expression
Posted 06 October 2012 - 11:53 PM
#3
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.
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
#4
Re: Data type mismatch in criteria expression
Posted 07 October 2012 - 03:38 PM
thank you sir!
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|