空間?我需要訪問其中一些客戶的路徑中有空格的文件夾。無法打開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();
這是公平地說,它沒有連接到數據庫,但它會很高興地知道實際的錯誤信息是什麼 –