Nick3
Nick3

Reputation: 639

Oledb, crash if DB path have spaces... C#

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

Upvotes: 0

Views: 1948

Answers (1)

kpcrash
kpcrash

Reputation: 330

Wrap the path in single quotes

    String connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + dbPath +"'"; //could use String.Format here as well.

Upvotes: 4

Related Questions