Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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 
btnAdd.Click
        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))
 

        myconnection.Open()
        cmd.ExecuteNonQuery()
        myconnection.Close()
 
        ClearTextBox(Me)
        RefreshDVG()
        Me.Close()
 

    End Sub
End Class
Posted 6-Oct-12 21:07pm
Rate this: bad
good
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)
 
cheers
  Permalink  
v2
Rate this: bad
good
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?
  Permalink  

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

  Print Answers RSS
0 /\jmot 230
1 Zoltán Zörgő 210
2 CHill60 145
3 Peter Leow 145
4 Sergey Alexandrovich Kryukov 125
0 Sergey Alexandrovich Kryukov 9,353
1 OriginalGriff 6,881
2 Peter Leow 4,577
3 Zoltán Zörgő 4,129
4 Richard MacCutchan 2,882


Advertise | Privacy | Mobile
Web01 | 2.8.150129.1 | Last Updated 7 Oct 2012
Copyright © CodeProject, 1999-2015
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