DBF files with broken dashes

Trying to do some work on reading and writing DBF files, and I found this example: http://www.aspcode.net/reading-dbf-files-in-c

System.Data.Odbc.OdbcConnection oConn = new System.Data.Odbc.OdbcConnection(); oConn.ConnectionString = @"Driver={Microsoft dBase Driver (*.dbf)};SourceType=DBF;SourceDB=D:\databases\;Exclusive=No; Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;"; oConn.Open(); System.Data.Odbc.OdbcCommand oCmd = oConn.CreateCommand(); oCmd.CommandText = @"SELECT * FROM D:\databases\thefile.dbf" ; DataTable dt = new DataTable(); dt.Load(oCmd.ExecuteReader()); oConn.Close(); dataGridView1.DataSource = dt; 

Only problem is that it does not work if the file or folder name has a dash (-) in it. Is there a way to make this query work with dashes in names?

eg. DBF File: C:\Temp\bowlpos\07-10\01-07-10.DBF

+4
source share
1 answer

try below

 using (OleDbConnection cn = new OleDbConnection( @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data Source=C:\Temp\bowlpos\07-10\01-07-10.DBF;" + @"Extended Properties=dBASE III;")) using (OleDbCommand cm = cn.CreateCommand()) { cn.Open(); cm.CommandText = "SELECT * FROM [01-07-10]"; DataTable dt = new DataTable(); dt.Load(cm.ExecuteReader()); dataGridView1.DataSource = dt; } 
+1
source

Source: https://habr.com/ru/post/1383782/


All Articles