Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 23rd, 2007, 02:11 AM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default data type mismatch in criteria expression

        Dim connectionString As String = dbconstr
        Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString )

        Dim queryString As String = "INSERT INTO [tblEmployees] " & _
         "([datEmpFirstName]," & _
         "[datEmpLastName]," & _
         "[datEmpDOB]," & _
         "[datEmpStartDate]," & _
         "[datCompanyID]," & _
         "[datEmpInitials]," & _
         "[datEmpIDNumber]," & _
         "[datLeaveID]," & _
         "[datBenefitID]," & _
         "[datDeductionID]," & _
         "[datNOKID]," & _
         "[datEmpNumberOfDependants]," & _
         "[datEmpOccupation]," & _
         "[datEmpCellNumber]," & _
         "[datEmpPassportNumber]," & _
         "[datEmpEmailAddress]," & _
         "[datEmpPostalAddress]," & _
         "[datEmpPostalCode]," & _
         "[datEmpResidentialAddress]," & _
         "[datEmpResidentialCode]," & _
         "[datEmpPhoneNumber]," & _
         "[datEmpEndDate]," & _
         "[datEmpPayFrequency]," & _
         "[datEmpPayMethod]," & _
         "[datEmpPaySlipLanguage]," & _
         "[datEmpBankName]," & _
         "[datEmpBankAccountType]," & _
         "[datEmpBankAccountNumber]," & _
         "[datEmpBankBranchName]," & _
         "[datEmpBankBranchCode]," & _
         "[datStatus]," & _
         "[datEmpRace]," & _
         "[datEmpOccupationalLevel]," & _
         "[datEmpOccupationalCategory]," & _
         "[datEmpdisability]," & _
         "[datEmpProvince]," & _
         "[datEmpExperience]," & _
         "[datEmpNationality]," & _
         "[datEmpPayDay]," & _
         "[datEmpSalary]" & _
            ") VALUES (" & _
          "'" & txtEmpFirstName.Text & "'," & _
          "'" & txtEmpLastName.Text & "'," & _
          "'" & dtpEmpDOB.Text & "'," & _
          "'" & dtpEmpStartDate.Text & "'," & _
          "'" & cmbCompanyID.Text & "'," & _
          "'" & txtEmpInitials.Text & "'," & _
          "" & nudEmpIDNumber.Value & "," & _
          "'" & cmbLeaveID.Text & "'," & _
          "'" & cmbBenefitID.Text & "'," & _
          "'" & cmbDeductionID.Text & "'," & _
          "'" & cmbNOKID.Text & "'," & _
          "" & nudEmpNumberOfDependants.Value & "," & _
          "'" & cmbEmpOccupation.Text & "'," & _
          "'" & txtEmpCellNumber.Text & "'," & _
          "'" & txtEmpPassportNumber.Text & "'," & _
          "'" & txtEmpEmailAddress.Text & "'," & _
          "'" & txtEmpPostalAddress.Text & "'," & _
          "'" & txtEmpPostalCode.Text & "'," & _
          "'" & txtEmpResidentialAddress.Text & "'," & _
          "'" & txtEmpResidentialCode.Text & "'," & _
          "'" & txtEmpPhoneNumber.Text & "'," & _
          "'" & dtpEmpEndDate.Text & "'," & _
          "'" & cmbEmpPayFrequency.Text & "'," & _
          "'" & cmbEmpPayMethod.Text & "'," & _
          "'" & cmbEmpPaySlipLanguage.Text & "'," & _
          "'" & cmbEmpBankName.Text & "'," & _
          "'" & cmbEmpBankAccountType.Text & "'," & _
          "'" & txtEmpBankAccountNumber.Text & "'," & _
          "'" & txtEmpBankBranchName.Text & "'," & _
          "'" & txtEmpBankBranchCode.Text & "'," & _
          "'active'," & _
          "'" & cmbEmpRace.Text & "'," & _
          "'" & cmbEmpOccupationalLevel.Text & "'," & _
          "'" & cmbEmpOccupationalCategory.Text & "'," & _
          "'" & cmbEmpDisability.Text & "'," & _
          "'" & txtEmpProvince.Text & "'," & _
          "'" & txtEmpExperience.Text & "'," & _
          "'" & cmbEmpNationality.Text & "'," & _
          "'" & dtpEmpPayDay.Text & "'," & _
          "" & nudEmpSalary.Value & "" & _
          ")"



        Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
        dbCommand.CommandText = queryString
        dbCommand.Connection = dbConnection

        Dim rowsAffected As Integer = 0
        dbConnection.Open()
        Try
            rowsAffected = dbCommand.ExecuteNonQuery
            MessageBox.Show(txtEmpLastName.Text & "," & txtEmpFirstName.Text & " has been added.", "The Adviser Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            'MessageBox.Show("A user already exist with such id number", "The Adviser Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            MsgBox(ex.Message)
            nudEmpIDNumber.Value = 0
            nudEmpIDNumber.Focus()
        Finally
            dbConnection.Close()
            clrfrm()
        End Try

 
Old March 23rd, 2007, 07:02 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

So what is the problem?

mmcdonal
 
Old March 23rd, 2007, 08:02 AM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by mmcdonal
 So what is the problem?

mmcdonal
was getting this error : data type mismatch in criteria expression,
but I solved it on my own. it was the dates in the query

 
Old March 23rd, 2007, 08:54 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Without knowing the data types in each field, this would be hard to troubleshoot.

mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
data type mismatch in criteria expression coreyjustin Classic ASP Basics 1 December 10th, 2007 06:49 PM
Data type mismatch in criteria expression Tawanda BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 0 May 5th, 2007 05:29 PM
Data type mismatch in criteria expression. imercha Classic ASP Basics 3 November 23rd, 2006 11:09 AM
Data type mismatch in criteria expression. EDEN Access ASP 1 November 22nd, 2006 01:19 AM
Data type mismatch in criteria expression. kalchev ASP.NET 2.0 Professional 5 April 11th, 2006 11:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.