Help Wanted: Loading Textfile Data Into Access

G

Guest

Hello. How should I go about loading data from a textfile into an Access
file? I want to do this via a C# program. Please note that:

(a) The Access file has 4 tables: Table1, Table2, etc. The data is to go in
Table1.

(b) Each row in the textfile corresponds with the fields in Table1.

(c) This is what I've been to pull together:

string strConn = "Provider = Microsoft.Jet.OLEDB.4.0;";
strConn += " Data Source = myTarget.mdb;" + "Extended Properties = text";
strConn += " HDR = Yes; FMT = Delimited";
strConn += " user id = ; password = ;";


OleDbConnection conn = new OleDbConnection(strConn);

conn.Open();

OleDbCommand c = new OleDbCommand("SELECT * FROM myFile.txt", conn);
OleDbDataReader r = null;

r = c.ExecuteReader();

while (r.Read())
{
for (int i = 0; i < r.FieldCount; i++)
{
//An INSERT Statement
}
}

conn.Close();


What am I doing wrong here? What is the way to go here? Thanks.

Regards.
 
D

david epsom dot com dot au

If I open visual studio, create a new project,
and paste that stuff into it, I will be able
to see what it does.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top