Solved

Import text files over to MS Access as Queries using C#

Posted on 2013-06-14
10
1,063 Views
Last Modified: 2013-06-18
Heyas,

Could someone give me some advice about what access functions I should research if I want to write a C# program that imports a selected series of txt files over into MS Access as queries.

Thank you.
0
Comment
Question by:Zack
  • 6
  • 4
10 Comments
 
LVL 57
ID: 39247791
Only thing built-in per say is the TransferText method in the Access application model.  You'd have to execute Access as a COM object to use that.

Beyond that, in Access you'd use VBA and regular file IO statements to read a file and then DAO or ADO objects (i.e. recordset) to store the data in a table.

The JET engine itself does have some ISAM capabilities, so using DAO, you could create a linked table directly on a text file, then use queries off that to read the data and save it in other table(s).

The text file needs to be well formed (consistent) to use that approach however.

Jim.
0
 
LVL 57
ID: 39247809
I just re-read your question and I think I missed the boat a bit.  This may be more along the lines of what you were looking for:

Walkthrough: Editing an Access Database with ADO.NET
http://msdn.microsoft.com/en-us/library/ms971485.aspx

Jim.
0
 

Author Comment

by:Zack
ID: 39249449
Heyas,

Just to clarify what I would like to do is the exact opposite of this.

http://stackoverflow.com/questions/1275502/using-vba-to-export-all-ms-access-sql-queries-to-text-files

Thank you.
0
 
LVL 57
ID: 39251255
You have text files then that you are trying to import into a JET DB as table data?

Is so, then then my first comment was not that far off.

If your saying that you have text files that are SQL statements and you want to create queries from them in a Access DB, then that is something else.

Jim.
0
 

Author Comment

by:Zack
ID: 39253003
Hi Jim,

If your saying that you have text files that are SQL statements and you want to create queries from them in a Access DB, then that is something else.

Close instead

I have text files that are SQL Queries and you want to import those text files and save them as SQL Queries in the Access DB.

Thank you.
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 57
ID: 39253023
I'm still confused over what you are trying to do.

 Do you have data in these text files that needs to be placed in tables

or

 Do you have SQL statements in text files that you want to save as queries?

a sample of one of the text files would be helpfull.

Jim.
0
 

Author Comment

by:Zack
ID: 39253321
Hi Jim
 

Do you have SQL statements in text files that you want to save as queries?


That one

Thank you.
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 39254343
Add a reference to the DAO object model:

c:\Program Files\Common Files\Microsoft Shared\DAO

Then do something like this:

// Create DAO Connection, Workspace & Database.
dao._DBEngine dbEngine = new dao.DBEngine();
dao.Workspace workSpace =
dbEngine.CreateWorkspace("MainWorkspace", "admin", "",
dao.WorkspaceTypeEnum.dbUseJet);
dao.Database db = workSpace.OpenDatabase(path, false,
false, Type.Missing);

// Create QueryDef
QueryDef query = db.CreateQueryDef("myQuery", "mySQLStatementText");

Jim.
0
 

Author Closing Comment

by:Zack
ID: 39254744
Thank you for the advice, my apologies my communication wasn't clear initially.
0
 
LVL 57
ID: 39256043
<<Thank you for the advice, my apologies my communication wasn't clear initially. >>

  No problem at all.  Was thinking that english may not be your native language...and no one should say their sorry for knowing more then one!

Jim.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now