Click here to Skip to main content
13,287,592 members (48,003 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 frmAdd
    Dim myconnection As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\order\Order\Order\Orders.accdb")
    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
    End Sub
    Private Sub frmAdd_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    End Sub
    Private Sub ClearTextBox(frmAdd As frmAdd)
    End Sub
    Private Sub RefreshDVG()
    End Sub

    Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles 
        Dim sqlinsert As String
        sqlinsert = "insert into Orders (ID, Description, U_Price, U_Quantity) VALUES (@ID, @Description,@U_Price,@U_Quantity)"
        Dim cmd As New OleDb.OleDbCommand(sqlinsert, myconnection)
        cmd.Parameters.Add(New OleDb.OleDbParameter("@ID", lblID.Text))
        cmd.Parameters.Add(New OleDb.OleDbParameter("@Description", txtDescription.Text))
        cmd.Parameters.Add(New OleDb.OleDbParameter("@U_Price", txtUprice.Text))
        cmd.Parameters.Add(New OleDb.OleDbParameter("@U_Quantity", txtUQuantity.Text))


    End Sub
End Class
Posted 6-Oct-12 21:07pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You need to specify datatype of "U_Price" and "U_Quantity" in OleDbParameter.

cmd.Parameters.Add("@U_Price", OleDbType.Integer).Value = Convert.ToIn32(txtUprice.Text);
//use the same for U_price (hopefully price is a decimal, s use the appropriate oledbtype)

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

how about deriving an attribute? w/c is The total of unit price and unit quantity?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171207.1 | Last Updated 7 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100