HighTechTalks DotNet Forums  

Text files and delimiters problem

Dotnet Framework (ADO.net) microsoft.public.dotnet.framework.adonet


Discuss Text files and delimiters problem in the Dotnet Framework (ADO.net) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Mike
 
Posts: n/a

Default 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



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.