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 7719335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:23:26+00:00 2026-06-01T03:23:26+00:00

Found very strange behavior of MS Access database when running queries from c#. It

  • 0

Found very strange behavior of MS Access database when running queries from c#. It appears that if query in MS Access contains “like” statement it will not return its result to Oledb. If anyone knows how to solve this I’ll be very grateful. c# code:

DataTable GetAccessData(string FileName, string Password)
    {
        Query = "select * from [qry_1]";
        DataTable DT = access2dt
            (
            FileName,Password,Query);

        MessageBox.Show(Query);
        if (DT == null || DT.Rows.Count <= 1) throw new Exception("Data not found");
        else return DT;
    }

public static DataTable access2dt(string filename, string password, string query)
{
    string conString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Jet OLEDB:Database Password=" + password;
    OleDbConnection mycon;
    mycon = new OleDbConnection(conString);

    if (mycon.State == ConnectionState.Closed)
    {
        mycon.Open();
    }
    try
    {
        OleDbCommand accessCommand = new OleDbCommand();
        System.Data.DataTable dt = new System.Data.DataTable();
        accessCommand = new OleDbCommand(query, mycon);

        using (OleDbDataReader myReader = accessCommand.ExecuteReader())
        {
            DataTable myTable = new DataTable();
            myTable.Load(myReader);
            return myTable;
        }
    }
    finally
    {
        mycon.Close();
    }

}

And query [qry_1] saved in MS Access database looks like this:

SELECT tbl_MAPPING_GICM_AoA.[Type of expense]
FROM tbl_USGAAP_ALL_TRANS, tbl_MAPPING_GICM_AoA
WHERE tbl_USGAAP_ALL_TRANS.[Account]=[tbl_MAPPING_GICM_AoA].[Natural Account]
AND tbl_USGAAP_ALL_TRANS.[Created By] NOT IN (SELECT [Created by / User ID] FROM tbl_GICM_AoA_EXCL_FACTOR1)
AND tbl_USGAAP_ALL_TRANS.[Je Source] NOT IN (SELECT [JE SOURCE] FROM tbl_GICM_AoA_EXCL_FACTOR2)
AND tbl_USGAAP_ALL_TRANS.[Je Category] NOT IN (SELECT [JE CATEGORY] FROM tbl_GICM_AoA_EXCL_FACTOR3)
AND (tbl_USGAAP_ALL_TRANS.[Account] LIKE '4*' OR tbl_USGAAP_ALL_TRANS.[Account] LIKE '5*'  OR tbl_USGAAP_ALL_TRANS.[Account] LIKE '6*' )

So when i run it in Access it works just fine but when i call this query from c# i get “Data not found” exception. If I remove the last string (with LIKE) in query everything starts working

  • 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-01T03:23:27+00:00Added an answer on June 1, 2026 at 3:23 am

    Try replacing the wildcard character. Access uses ‘*’, but using OLEDB you will need to use ‘%’ as the wildcard.

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

Sidebar

Related Questions

One thing I have continually found very confusing about using an object database like
I've found very strange C# compiler behavior for following code: var p1 = new
Ladies and gents, I found a very strange behavior which I cannot explain: Assume
I recently started learning Java and found it very strange that every Java public
Yesterday I found something very strange (I think). It looks like Form.TransparencyKey gives different
I am having a very strange behavior in JBoss, and I'd like avail myself
I have found a very strange occurrence in Android. I have found that when
We have encountered a very strange class not found problem in our web app
I found it very hard to customize PDF invoice that Magento use. Not only
I found out really strange behavior on relatively simple use case, probably I can't

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.