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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:39:35+00:00 2026-05-28T07:39:35+00:00

I am automating Microsoft Access from C# like so: using Microsoft.Office.Interop.Access; static void Main(string[]

  • 0

I am automating Microsoft Access from C# like so:

using Microsoft.Office.Interop.Access;

static void Main(string[] args)
{
    Application ap = new Application();

    ap.OpenCurrentDatabase("C:\\location.accdb", true);
    ap.DoCmd.WhateverIFeelLike();
    ap.CloseCurrentDatabase();
}

What I want to do here is run one of the select queries stored within Access and return this value either as a string or string array.

I want something like this:

string[] myQueryResult = ap.DoCmd.OpenQuery("qryFoo");

Obviously this doesn’t work but this the kind of thing that I am looking for. As a workaround I am thinking of exporting the query results to a CSV file then using Filehelpers to import this into an Array in C# but I thought I would ask on here first in the hope that there is a more direct route!

Thanks

  • 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-05-28T07:39:36+00:00Added an answer on May 28, 2026 at 7:39 am

    A possibility is to use OleDb. You need to build your project with “x86” as platform target on 64-bit machines, since the Jet drivers are 32-bit.

    const string DatabasePath = @"C:\DbPath\MyDatabase.mdb";
    const string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
                                    DatabasePath;
    
    using (OleDbConnection cnn = new OleDbConnection(ConnectionString)) {
        string query = "SELECT * FROM qryFoo";
        using (OleDbCommand cmd = new OleDbCommand(query, cnn)) {
            cnn.Open();
            using (OleDbDataReader reader = cmd.ExecuteReader()) {
                int employeeIdOrdinal = reader.GetOrdinal("EmployeeID");
                int nameOrdinal = reader.GetOrdinal("Name");
                int salaryOrdinal = reader.GetOrdinal("Salary");
                while (reader.Read()) {
                    Console.WriteLine("EmployeeID = {0}", reader.GetInt32(employeeIdOrdinal));
                    Console.WriteLine("Name = {0}", reader.GetString(nameOrdinal));
                    if (!reader.IsDBNull(salaryOrdinal)) {
                        Console.WriteLine("Salary = {0}", reader.GetDouble(salaryOrdinal));
                    }
                    Console.WriteLine("---------------");
                }
            }
        }
    }
    

    You do not need Access interop for this to work, however a using System.Data.OleDb;

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

Sidebar

Related Questions

I got an application that automates Microsoft Excel (2003) using Office Automation. One of
I'm having trouble deploying .NET application which uses Microsoft Access automation. I've installed the
When using Microsoft office automation I want to insert images into a spreadsheet. How
Background I am automating some Office application (Word and PowerPoint) via command-line tool. One
I'm automating Visio 2003 from a VB.NET app. My code looks like this (with
I'm trying to automate menu picks using Microsoft UI Automation. The application that I'm
I have some C# automation code which does interesting things with Microsoft.Office.Interop.Word.Document objects. The
I am automating Word, so I would like to suppress all alerts. Word.Application word
I am currently trying to automate a Windows Forms application by using the Microsoft
When using COM Interop with Office (usually Excel), I always carefully ensure I call

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.