private void Form1_Load(object sender, EventArgs e)
{
GetDataTable(@"C:\Documents and Settings\agordon\Desktop\ACTIVITYEX.log");
}
public System.Data.DataTable GetDataTable(string strFileName)
{
System.Data.OleDb.OleDbConnection conn =
new System.Data.OleDb.OleDbConnection
("Provider=Microsoft.Jet.OleDb.4.0; Data Source = "
+ System.IO.Path.GetDirectoryName(strFileName)
+ ";Extended Properties = \"Text;HDR=YES;FMT=TabDelimited\"");
conn.Open();
string strQuery = "SELECT * FROM [" + System.IO.Path.GetFileName(strFileName) + "]";
System.Data.OleDb.OleDbDataAdapter adapter = new System.Data.OleDb.OleDbDataAdapter(strQuery, conn);
System.Data.DataTable ds = new System.Data.DataTable("CSV File");
adapter.Fill(ds);
return ds;
}
when THE SAME file is named .csv it does not give me an error; however when i rename it to .log it says Cannot update. Database or object is read-only. on adapter.Fill
is this a compiler error?
An old post, but I just stepped into that problem. Please refer to this article : https://support.microsoft.com/en-us/kb/245407
Long story short : Jet Engine only accepts a few file extension when reading CSV File (Extended properties=TEXT,etc..).
Solutions :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With