string hdr = "No";
string fmt = "Delimited( )";
string folderPath = SpecialDirectories.CurrentUserApplicationData;
string fileName = "temp.tmp";
string connStr =
string.Format(
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source='{0}';Extended
Properties='text;HDR={1};FMT={2}'",
folderPath, hdr, fmt);
string textFileSql = string.Format("SELECT * FROM [{0}]", fileName);
using (OleDbConnection conn = new OleDbConnection(connStr))
{
OleDbDataAdapter inputAdapter =
new OleDbDataAdapter(textFileSql, conn);
DataTable inputTable = new DataTable();
inputAdapter.Fill(inputTable);
Console.WriteLine(inputTable.Columns.Count);
Console.WriteLine(inputTable.Rows.Count);
}
"717600438" "blat"
"717900172" "blat"
"718000182" " "
"718000238" " "
In the connection string, we can only specify "Fixed" or "Delimited" for
the FMT property. If we want to control over the delimiter type used in the
text file, we need use the Schema.INI file.
When the Text driver is used, the format of the text file is determined by
using a schema information file. The schema information file is always
named Schema.ini and always kept in the same directory as the text data
source. The schema information file provides the IISAM with information
about the general format of the file, the column name and data type
information, and several other data characteristics. A Schema.ini file is
always required for accessing fixed-length data.
More detailed information, please read the following articles,
http://support.microsoft.com/kb/326548
http://msdn.microsoft.com/en-us/library/ms709353.aspx
Please let me know if you have any future questions or concerns on this.
Have a nice weekend!
Best regards,
Colbert