Text files and delimiters problem -
09-08-2007
, 06:19 PM
Code:
string connect = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=|DataDirectory|Contacts.mdb";
OleDbConnection conn = new OleDbConnection(connect);
string path = Server.MapPath("App_Data");
string query = "INSERT INTO Persons (FirstName, SecondName) SELECT F1, F2
FROM [Text;HDR=NO;FMT=TabDelimited;DATABASE=" + path + ";].[test.txt]";
OleDbCommand cmd = new OleDbCommand(query, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
Schema.ini:
[Sample.txt]
Format=TabDelimited
ColNameHeader=False
Col1=F1 TEXT width 50
Col2=F2 TEXT width 50
CharacterSet=ANSI
Sample.txt contents:
Joe Bloggs
Fred Bassett
Archie Falls
Doris Knight
Gladys Day
On one machine, this works fine. On another - which is, as far as I know,
set up exactly the same - the code throws a "No value given for one or more
required parameters" exception. When I paste the command text from the
Locals window into the query builder in Access and attempt to run it, I get
prompted for a value for F2. I supply one and the values get inserted.
However, both columns get inserted into the FristName filed with a square
box separating them. Clearly, the delimiter is not being recognised. I've
also tried with a variety of other delimiters with the same result. Can
anyone offer a suggestion as to what gives?
Mike |