|
-
Jan 4th, 2008, 10:18 PM
#1
Thread Starter
Member
[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.
-
Jan 5th, 2008, 01:10 AM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 5th, 2008, 01:35 AM
#3
Thread Starter
Member
Re: MS Access 2003+VB.Net 2005+Data type mismatch
 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.
-
Jan 5th, 2008, 02:25 AM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 5th, 2008, 02:26 AM
#5
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
-
Jan 5th, 2008, 02:28 AM
#6
Thread Starter
Member
Re: MS Access 2003+VB.Net 2005+Data type mismatch
-
Jan 5th, 2008, 02:32 AM
#7
Member
Re: MS Access 2003+VB.Net 2005+Data type mismatch
 Originally Posted by Wulfgur
Edit: trying that now.
since you're using ADO.NET? why don't you use parameters?
-
Jan 5th, 2008, 02:47 AM
#8
Thread Starter
Member
Re: MS Access 2003+VB.Net 2005+Data type mismatch
Ok thanks all for the help, it seems to be working fine.
-
Jan 5th, 2008, 05:35 AM
#9
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|