Click here to Skip to main content
12,396,461 members (69,467 online)

data type mismatch in criteria expression

Member 9766489 asked:

Open original thread
m getting this error "data type mismatch in criteria expression" in the line cd=oledbcom.executeNonQuery() in insert section

herz the code:
Imports System.Data.OleDb
 

Public Class Form1
 
    Dim oledbconn As OleDbConnection
    Dim oledbcom As OleDbCommand
    Dim oledbreader As OleDbDataReader
    Dim connectionString As String
    Dim command As String
    Dim cd As Integer
 

 

 

   
 
    Private Sub open_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles open.Click
        
 
        connectionString = "provider= Microsoft.Jet.OLEDB.4.0;Data source=Student.mdb"
 
        oledbconn = New OleDbConnection(connectionString)
        MsgBox("database connected")
        
       
    End Sub
 
    Private Sub fillreader_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fillreader.Click
        
        connectionString = "provider= Microsoft.Jet.OLEDB.4.0;Data source=Student.mdb"
 

        command = "select * from personinfo"
        oledbcom = New OleDbCommand(command, oledbconn)
        Try
            oledbreader = oledbcom.ExecuteReader()
            If (oledbreader.Read()) Then
                Txtroll.Text = oledbreader(0)
                Txtname.Text = oledbreader(1)
                txtemail.Text = oledbreader(2)
                Txtphone.Text = oledbreader(3)
                Txtpercentage.Text = oledbreader(4)
            End If
        Catch ex As Exception
 
        End Try
        
 

    End Sub
 
    Private Sub close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles close.Click
       
 
        oledbconn.Close()
        MsgBox("database disconnected")
 

 
    End Sub
 
    Private Sub insert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles insert.Click
        
        connectionString = "provider= Microsoft.Jet.OLEDB.4.0;Data source=Student.mdb"
 
        oledbconn.Open()
 
        command = "insert into personinfo values('&Txtroll.text&','&Txtname.text&','&Txtemail.text&','&Txtphone.text&','&cint(Txtpercentage.text)&')"
        oledbcom = New OleDbCommand(command, oledbconn)
        cd = oledbcom.ExecuteNonQuery()
        MsgBox("data is entered in database")
 

 
        
 

    End Sub
 
    Private Sub Txtroll_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Txtroll.TextChanged
 
    End Sub
 
    Private Sub Txtname_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Txtname.TextChanged
 
    End Sub
End Class
Tags: VB, VB.NET

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web01 | 2.8.160721.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2016
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