Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8627425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:16:38+00:00 2026-06-12T08:16:38+00:00

I’m trying to update a value in a MS Access DB (*.mdb) using OleDB

  • 0

I’m trying to update a value in a MS Access DB (*.mdb) using OleDB in C#. Nothing fancy, except that I need to choose the row by an binary value, a VARBINARY(4).

Naively I thought UPDATE MYTABLE SET VALUE= 'new' WHERE BINVALUE=01020304; would work. But is does not.
Alternative tries were:

UPDATE MYTABLE SET VALUE= 'new' WHERE BINVALUE='01020304';
UPDATE MYTABLE SET VALUE= 'new' WHERE BINVALUE='0x01020304';
UPDATE MYTABLE SET VALUE= 'new' WHERE BINVALUE=0x01020304;
UPDATE MYTABLE SET VALUE= 'new' WHERE BINVALUE=CAST('01020304' as VARBINARY);
UPDATE MYTABLE SET VALUE= 'new' WHERE BINVALUE=CAST(01020304 as VARBINARY);
UPDATE MYTABLE SET VALUE= 'new' WHERE BINVALUE=CAST('01020304' as VARBINARY(4));
UPDATE MYTABLE SET VALUE= 'new' WHERE BINVALUE=CAST(01020304 as VARBINARY(4));
UPDATE MYTABLE SET VALUE= 'new' WHERE BINVALUE=CONVERT(varbinary(4),'01020304');
UPDATE MYTABLE SET VALUE= 'new' WHERE CAST(BINVALUE as VARCHAR(MAX)) = CAST('01020304' as VARCHAR(MAX));
UPDATE MYTABLE SET VALUE= 'new' WHERE CAST(BINVALUE as VARCHAR(MAX)) = CAST(01020304 as VARCHAR(MAX));
UPDATE MYTABLE SET VALUE= 'new' WHERE CONVERT(VARCHAR(MAX), BINVALUE) = CONVERT(VARCHAR(MAX), '01020304');

Using CAST results in a syntax error exception: missing operator.

Using CONVERT results in exception: Undefined function 'CONVERT' in expression.

The number of affected rows, in int result, is always zero. Using UPDATE MYTABLE SET VALUE= 'new' WHERE VALUE= old; works, but will sometimes hit more than one row.

While trying and failing to find a way to circumvent checking BINVALUEI noticed that you should not use Arabic commas (‘) around values in the WHERE clause. UPDATE MYTABLE SET VALUE= 'new' WHERE VALUE='old'; does NOT work while UPDATE MYTABLE SET VALUE= 'new' WHERE VALUE=old; works.

Using MS Query yields different results concerning the Arabic commas:

UPDATE MYTABLE SET VALUE='new' WHERE BINVALUE='01020304' executes, but has no effect.

UPDATE MYTABLE SET VALUE='new' WHERE BINVALUE=01020304 results in the error message “Syntax error in number in query expression ‘BINVALUE=01020304’.”

I can’t reproduce the error message “Column BINVALUE can’t be used in the criteria.” that I mentioned in the comments.

Using other columns to identify the desired row does not work, as most values are the same. Strangely enough BINVALUE serves as a the primary key.

On top of that, I am not allowed to change the DB schema, as a legacy application needs it exactly that way.

Based on gloomy.penguin’s input I assume there is a problem with the type casting/matching in the WHERE clause. This leads to the question how casting/conversion is done in OleDB or Access as the CAST operator appears to be known, but CONVERT is not. My guess would be that CAST has another syntax than in standard SQL for whatever reasons.

Any suggestions, how this update query can be made to work?

This is my stripped down example code:

static String ToHexString(Byte[] buffer)
{
    String str;
    str = BitConverter.ToString(buffer).Replace("-", string.Empty);
    return (str);
}

...

String table = "MYTABLE";
String newvalue = "new";
Byte[] binvalue = { 1, 2, 3, 4 };

String providerStr= @"Provider=Microsoft.JET.OLEDB.4.0;" + @"data source=C:\myDB.mdb";
connection = new OleDbConnection(providerStr);
connection.Open();

String cmd = @"UPDATE " + table + " SET VALUE= '" + newvalue + "'"
    + " WHERE BINVALUE= '" + ToHexString(binvalue) + "'"
    + ";";

OleDbCommand command = new OleDbCommand(cmd, connection);
int result = command.ExecuteNonQuery();

connection.Close();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:16:39+00:00Added an answer on June 12, 2026 at 8:16 am

    I figured out a way to solve the type casting issue I have been facing.
    Apparently it is not possible using SQL syntax, but using a command with parameters.

    Instead of:

    String cmd = @"UPDATE " + table + " SET VALUE= '" + newvalue + "'"
        + " WHERE BINVALUE= '" + ToHexString(binvalue) + "'"
        + ";";
    
    OleDbCommand command = new OleDbCommand(cmd, connection);
    int result = command.ExecuteNonQuery();
    

    I had to use:

    String cmd = @"UPDATE " + table + " SET VALUE= '" + newvalue + "'"
        + " WHERE BINVALUE= @binval" + ";";
    
    OleDbCommand command = new OleDbCommand(cmd, connection);
    
    OleDbParameter param = new OleDbParameter();
    param.OleDbType = OleDbType.Binary;
    param.ParameterName = "binval";
    param.Value = binvalue;
    command.Parameters.Add(param);
    
    int result = command.ExecuteNonQuery();
    

    Of course it would be cleaner to add all parameters this way. I omitted that to highlight the important part.

    For further reading, an example of how to read and write images as binary data to a DB
    on the C# helper blog.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.