This is all C# code but you should be able to follow along on the
simplicity of it.  When you have a problem in the load call out ot OLEDB
for a heavy lift.

 public DataTable OpenCsvFileAsDataTable(string fileName, bool
firstLineIsHeader)
{
    DataTable result = new DataTable();
    System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName);

    // The table name is the actual name of the file.
    string tableName = fileInfo.Name;

    // Get the folder name in which the file is. This will be part of the
    // connection string.
    string folderName = fileInfo.DirectoryName;
    string connectionString = "Provider=Microsoft.Jet.OleDb.4.0;" +
                              "Data Source=" + folderName + ";" +
                              "Extended Properties=\"Text;" +
                              "HDR=" + (firstLineIsHeader ? "Yes" : "No") +
";" +   IIF() here
                              "FMT=Delimited\"";

    using (System.Data.OleDb.OleDbConnection connection =
        new System.Data.OleDb.OleDbConnection(connectionString))
    {
        // Open the connection
        connection.Open();

        // Set up the adapter and query the table.
        string sqlStatement = "SELECT * FROM " + tableName;
        using (System.Data.OleDb.OleDbDataAdapter adapter =
            new System.Data.OleDb.OleDbDataAdapter(sqlStatement,
connection))
        {
            result = new DataTable(tableName);
            adapter.Fill(result);
        }
    }

    return result;
}

-- 
Stephen Russell
Sr. Analyst
Ring Container Technology
Oakland TN

901.246-0159 cell


--- StripMime Report -- processed MIME parts ---
multipart/alternative
  text/plain (text body -- kept)
  text/html
---

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/cajidmyj-fk0sr9_e30hyf4esdgfeju9a6pqzd7ua4zq9ca6...@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to