我正在尝试使用system.data.odbc.odbcconnection查询DBF文件。当文件中没有空间时,它可以正常工作,但是我会收到以下错误“打开DBF文件:错误[42000] [Microsoft] [ODBC DBASE驱动程序]语法错误从子句中的语法错误”名称中有一个空间。

我正在使用以下代码:

oconn = new System.Data.odbc.odbcconnection(); oconn.connectionstring =“ driver = {Microsoft DBase driver(*.dbf)}; sourcetype = dbf; sourcedb; sourcedb = na; repuliveusive = no; colalate = no; colalate = machine; null = no; deleted; deleted = no; backowstfetch = no;

ocmd.commandText =“从c: test 2 12345678.dbf” select * select *。

命令文本没有硬编码。我只是为了简单起见而将其包括在内。该应用程序已设置为允许用户选择DBF文件并将其显示。我无法控制用户存储DBF文件的位置,也不必让他们记住不要将空格放在文件名/路径中。

如何逃脱文件名/路径中的空间?

有帮助吗?

解决方案

可能是与“ MS-DOS 8.3文件名格式”有关的问题。您可以查看下一个链接:

其他提示

我也遇到了这个问题。这是我在Google中排名第一的人,所以我不是很有希望。但是,我们能够通过将当前目录更改为有问题的目录,然后排除命令文本中的路径:

//Save the current directory
string currentDir = System.IO.Directory.GetCurrentDirectory();

//Select the path that we need to use
System.IO.Directory.SetCurrentDirectory("C:\\test 2\\");

//Now the path isn't required:
oCmd.CommandText = @"SELECT * FROM 12345678.dbf";

//Restore the old directory
System.IO.Directory.SetCurrentDirectory(currentDir);

您的名称可能是限制的(我认为没有空格,<= 8个字符),但这是我可以使用的东西。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top