Results 1 to 9 of 9

Thread: [RESOLVED]MS Access 2003+VB.Net 2005+Data type mismatch

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    63

    Resolved [RESOLVED]MS Access 2003+VB.Net 2005+Data type mismatch

    Hey,

    I'm currently using Visual Basic 2005, MS Access 2003 and OleDb Connection.
    This is my database module i use:

    Code:
    Module Database
    
        Public Connection As New OleDb.OleDbConnection
        Public ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database.mdb"
        Public Command As OleDb.OleDbCommand
        Public Reader As OleDb.OleDbDataReader
    
    End Module
    This is the code i am trying to execute.

    Code:
                Dim i
                Dim Customer As String
                Dim items As String
                Dim price As Double
    
                Command = Connection.CreateCommand
    
                For i = 0 To Checkoutbox.Items.Count - 1
                    Customer = Customerlist.SelectedItem.ToString
    
                    items = items + "and " + Checkoutbox.Items.Item(i).text
    
                    price = price + Checkoutbox.Items.Item(i).SubItems(1).Text()
    
    Command.CommandText = "INSERT INTO Transactions VALUES ('" & "" & "','" & Customer & "','" & items & "','" & price & "','" & System.DateTime.Today & "');"
                  
                Next
                
      Command.ExecuteNonQuery()
    The Error is: Data type mismatch in criteria expression.

    The first field in my database is an autonumber field.
    When inserting data into the table i want the autonumber field to just fill itself in. I don't know what to put into the database statement.

    Code:
    Command.CommandText = "INSERT INTO Transactions VALUES ('" & "" & "','" & Customer & "','" & items & "','" & price & "','" & System.DateTime.Today & "');"
    The Fields for the database are:
    Transaction_ID: Data Type: Autonumber - Primary Key
    Transaction_Customer: Data Type: Text
    Transaction_Items: Data Type: Text
    Transaction_Price: Data Type: Currency
    Transaction_Date: Data Type: Date/Time

    Hope that makes sense.
    Last edited by Wulfgur; Jan 5th, 2008 at 04:03 PM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: MS Access 2003+VB.Net 2005+Data type mismatch

    Waht is your last field's data type? You are inserting a date/time value but as a string? Also since you are not listing out your fields you need to make sure you are inserting the correct values in the correct fields as it goes by order when not listed.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    63

    Re: MS Access 2003+VB.Net 2005+Data type mismatch

    Quote Originally Posted by RobDog888
    Waht is your last field's data type?
    The last fields data type is: Date/Time

    Yes i am inserting the values in the correct order i have checked.

    I am trying to find out what i have to put into the statement if the data type is: Autonumber

    Code:
    Command.CommandText = "INSERT INTO Transactions VALUES ('" & "What do i put in here?" & "','" & Customer & "','" & items & "','" & price & "','" & System.DateTime.Today & "');"
    What do i put into the section "What do i put in here" If the datatype is an autonumber
    Last edited by Wulfgur; Jan 5th, 2008 at 01:39 AM.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: MS Access 2003+VB.Net 2005+Data type mismatch

    You leave the autonumber field out of the statement.

    Since the last field is date/time you should not be using quotes around the value. Use the # character instead which signifies a date literal.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: MS Access 2003+VB.Net 2005+Data type mismatch

    Well, that aside, you're getting errors because you didn't list out the fields in the table to insert into.... so it's taking the first value and trying to stuff it into the first field in the table, your autonumber.... clearly that aint' going to work.

    it should be a fully qualified insert, like this:
    Code:
    INSERT INTO tblMine (Field2, Field3, Field4,...Fieldx) VALUES ('Field2Val', 1, 3,...'ValueX')
    Note, that I SKIPPED Field1.... since it is an autonumber, we do NOT want to insert any data into it.... so we skip it (in effect, this attempts to insert a NULL value and force the DB to recognize that it is an autonumber and generate the next number in the sequence.)


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    63

    Re: MS Access 2003+VB.Net 2005+Data type mismatch

    Edit: trying that now.

  7. #7
    Member
    Join Date
    Nov 2006
    Posts
    38

    Re: MS Access 2003+VB.Net 2005+Data type mismatch

    Quote Originally Posted by Wulfgur
    Edit: trying that now.
    since you're using ADO.NET? why don't you use parameters?

  8. #8

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    63

    Re: MS Access 2003+VB.Net 2005+Data type mismatch

    Ok thanks all for the help, it seems to be working fine.

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: MS Access 2003+VB.Net 2005+Data type mismatch

    If everything is solved on this topic now dont forget to Resolve your thread from the Thread Tools menu so other members know its done.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width