• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1218
  • Last Modified:

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

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
Zack
Asked:
Zack
  • 6
  • 4
1 Solution
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
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
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
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
 
ZackGeneral IT Goto GuyAuthor Commented:
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
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
 
ZackGeneral IT Goto GuyAuthor Commented:
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
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
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
 
ZackGeneral IT Goto GuyAuthor Commented:
Hi Jim
 

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


That one

Thank you.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
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
 
ZackGeneral IT Goto GuyAuthor Commented:
Thank you for the advice, my apologies my communication wasn't clear initially.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<<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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now