问题
I have a problem that I thought someone may be able to help me with, I have a C# application that uses a Access-database. If my path is without spaces like "C:/Test/db.accdb" it works like a charm, but if the path got spaces like "C:/Test folder/db.accdb", not so much... does anyone know why this is? my code looks like this: (The query is just an example, you get the point :)
String connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + dbPath;
OleDbConnection connection = new OleDbConnection(connectionString);
OleDbCommand command;
connection.Open();
command = new OleDbCommand("UPDATE Table SET Tablevalue = 1 WHERE Tablevalue2 = 3")
command.ExecuteNonQuery();
connection.Close();
Thanks!
/Nick
回答1:
Wrap the path in single quotes
String connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + dbPath +"'"; //could use String.Format here as well.
来源:https://stackoverflow.com/questions/9925369/oledb-crash-if-db-path-have-spaces-c-sharp