空间?我需要访问其中一些客户的路径中有空格的文件夹。无法打开DBF在使用以下工作路径
file1 = "C:\\test1\\file.dbf";
file2 = "C:\\test 2\\file.dbf";
OdbcConnection Connection = new OdbcConnection();
Connection.ConnectionString = @"Driver={Microsoft Visual FoxPro Driver};Exclusive=No;SourceType=DBF;SourceDB=" + strFilename + ";";
Connection.Open();
OdbcCommand Command = Connection.CreateCommand();
Command.CommandText = @"SELECT * FROM " + file1; //Command.CommandText = @"SELECT * FROM " + file2;
执行一次 Connection.Open(); 它正确打开它,
一旦我们执行 OdbcDataReader Reader = Command.ExecuteReader();
我得到{System.Data.Odbc.OdbcException:ERROR [42S02] [Microsoft] [ODBC Visual FoxPro Driver] File'file2.dbf'不存在。
答案,因为我没有足够的代表
感谢大家的贡献,解决我的问题。该解决方案要求我放置完整路径(其中有一个空格)并使用@ char将其设置为字符串。由于某些原因,通过将转义字符(“\”“)加上引号并未解决问题。
总之,我在连接字符串和命令字符串的路径前面使用了@ @
strFilename = S.ImportFolder + "\\" +"file"+ ".dbf";
OdbcConnection Connection = new OdbcConnection();
Connection.ConnectionString = @"Driver={Microsoft Visual FoxPro Driver};Exclusive=No;SourceType=DBF;SourceDB="[email protected]+";";
Connection.Open();
OdbcCommand Command = Connection.CreateCommand();
Command.CommandText = @"SELECT * FROM "+ @strFilename;
OdbcDataReader Reader = Command.ExecuteReader();
这是公平地说,它没有连接到数据库,但它会很高兴地知道实际的错误信息是什么 –