Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-07-23
5
Medium Priority
?
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

610 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