Solved

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

Posted on 2006-07-23
5
313 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

726 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