C
csharpwalah
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.
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.