当文件路径/名称有空格时,使用 System.Data.Odbc.OdbcConnection 查询 DBF 文件
我正在尝试使用 System.Data.Odbc.OdbcConnection 查询 DBF 文件。当文件中没有空格时它可以正常工作,但如果文件路径或名称中有一个空格。
我使用以下代码:
oConn = new System.Data.Odbc.OdbcConnection(); oConn.ConnectionString = "Driver={Microsoft dBase Driver (*.dbf)};SourceType=DBF;SourceDB=NA;Exclusive=No; Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";
oCmd.CommandText = "从 C:\test 2\12345678.dbf 选择 *";
命令文本不是硬编码的。为了简单起见,我只是这样包含它。该应用程序设置为允许用户选择 DBF 文件并显示它。我无法控制用户存储 DBF 文件的位置,并且不想让他们记住不要在文件名/路径中添加空格。
如何转义文件名/路径中的空格?
I'm trying to query a DBF file using System.Data.Odbc.OdbcConnection. It works correctly when the file doesn't have a space in it, but I get the following error "Error opening DBF File: ERROR [42000][Microsoft][ODBC dBase Driver]Syntax error in FROM clause" if the file path or name has a space in it.
I'm using the following code:
oConn = new System.Data.Odbc.OdbcConnection();
oConn.ConnectionString = "Driver={Microsoft dBase Driver (*.dbf)};SourceType=DBF;SourceDB=NA;Exclusive=No; Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";
oCmd.CommandText = "SELECT * FROM C:\test 2\12345678.dbf";
The command text isn't hard-coded. I just included it that way for simplicity. The application is setup to allow a user to pick a DBF file and have it display it. I don't have control over where the users store the DBF files and would rather not have to have them remember not to put spaces in the file name/path.
How do I escape the space in the file name/path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能是与“MS-DOS 8.3 文件名格式”相关的问题。
您可以查看以下链接:
Probable it's a problem related with the "MS-DOS 8.3 file name format" .
You can review the next links:
我也遇到了这个问题。这是我在谷歌排名第一的热门产品,所以我并没有抱太大希望。但是,我们能够通过将当前目录更改为有问题的目录,然后排除 CommandText 中的路径来使我的代码正常工作:
您仍然受到文件名的限制(没有空格和 <= 8 个字符)我想),但这是我可以合作的。
I was running into this issue as well. This was my #1 hit in Google, so I wasn't very hopeful. However, we were able to get my code to work by changing the current directory to the problematic directory and then excluding the path in the CommandText:
You're still limited in what the file's name can be (no spaces and <= 8 char I think), but that's something I can work with.