Solved

Data type mismatch error when updating a record in a Access Database

Posted on 2006-07-23
5
308 Views
Last Modified: 2012-06-27
Hello experts

I am creating a website using VWD and an Access database.  I am having a problem when attempting to update a record in my database.  

The error I am getting is:

"Data type mismatch in criteria expression."

The error is thrown at this line of code:

da1.Update(ds1)

I've added some message boxes to show the current dataset value and it is updating correctly, however when it trys to update the actual database it dies.

Here is the code.

        Dim ds1 As New Data.DataSet()
        Dim SQL1 As String = "SELECT Week1.[1], Week1.ID FROM Week1 WHERE (((Week1.Username)=" & """" & Username & """" & "));"
        Dim da1 As New Data.OleDb.OleDbDataAdapter(SQL1, conn)
        da1.Fill(ds1)
        Dim cb1 As New Data.OleDb.OleDbCommandBuilder(da1)

        'For debugging purposes
        MsgBox("The dataset is currently: " & ds1.Tables(0).Rows(0)("1"))  <---- Shows the dataset before making the change

        ds1.Tables(0).Rows(0)("1") = Game1

        'For debugging purposes
        MsgBox("The dataset is now: " & ds1.Tables(0).Rows(0)("1"))  <---- the dataset updates correctly

        da1.Update(ds1)   <---- here is where the error is thrown

Ive spent four hours trying to figure this out!  Please help!
0
Comment
Question by:xfungalx
5 Comments
 
LVL 6

Expert Comment

by:Nandakumar Sakthivel
ID: 17165904

I think there is a mismatch between the tables datatype and the value you are sending

for example
 empty string value in the command text (SQL) cannot be stored in MS Access' "Date/Time"

Go thro' this link

http://www.xlinesoft.com/asprunner/docs/error_data_type_mismatch_in_criteria_expression.htm
http://support.microsoft.com/default.aspx/kb/175258

Thanks,
Nanda
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17166797
1) Does the data have single quotes in it?

2) What does the UpdateCommand and InsertCommand look like?

Bob
0
 
LVL 1

Expert Comment

by:awabid
ID: 17167540
Hello

try changing data type of your required fields from the one u have selected to chararray or text or string or something to the effect available in dropdown list of the field type of the access database. you probably need to change all the fields which are likely to be affected. I will appriciate if you post the access table design view as well, so that it is more clear. but i'm pretty sure changing the data type to string or something to the effect in the database will surly resolve your problem. be careful, there might be data loss when attempting to change the fields. backup your table if you have data in it.
0
 
LVL 41

Accepted Solution

by:
graye earned 500 total points
ID: 17167851
Hummm, We could try this....

Since you've got a strange column name (you rarely see a number as a column name) I'd bet the UpdateCommand and InsertCommands are throughly confused.  So I'd suggest that you set the QuotePrefix and QuoteSuffix properties like this:

cb1.QuotePrefix = "["
cb1.QuoteSuffix = "]"

http://msdn2.microsoft.com/en-us/library/system.data.oledb.oledbcommandbuilder_members.aspx

BTW:  Renaming the column would be my first choice
0
 

Author Comment

by:xfungalx
ID: 17168206
Graye you nailed it, works great now!  I renamed the column to "FirstGame" and updated my code as required and boom it worked.  

Thanks to everyone who contributed!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now