Sunday, February 20, 2011

Accessing Text Files using ODBC Data Provider

private void Form1_Load(object sender, System.EventArgs e)
{
// Connection string for a Text File
string ConnectionString = @"Driver={Microsoft Text Driver (*.txt; .csv)};DBQ=c:\";
// Query the Employees.txt file as a table
OdbcConnection conn = new OdbcConnection(ConnectionString);
conn.Open();
OdbcDataAdapter da = new OdbcDataAdapter("Select * FROM Employees.txt", conn);
DataSet ds = new DataSet();
da.Fill(ds, "TextDB");
dataGrid1.DataSource = ds.DefaultViewManager;
// Close the connection
conn.Close();
}

No comments:

Post a Comment