gpt4 book ai didi

c# - 带破折号的 DBF 文件不起作用

转载 作者:行者123 更新时间:2023-11-30 12:50:50 25 4
gpt4 key购买 nike

尝试做一些读写 DBF 文件的工作,我发现了这个示例: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;

唯一的问题是,如果文件或文件夹名称中有破折号 (-),它就不起作用。有什么方法可以让这个查询在名称中使用破折号吗?

例如。 DBF 文件:C:\Temp\bowlpos\07-10\01-07-10.DBF

最佳答案

试试下面

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;
}

关于c# - 带破折号的 DBF 文件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8320341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com