Oledb,如果数据库路径中有空格,则崩溃... C# [英] Oledb, crash if DB path have spaces... C#

查看:71
本文介绍了Oledb,如果数据库路径中有空格,则崩溃... C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我认为有人可以为我提供帮助,我有一个使用Access数据库的C#应用​​程序.如果我的路径中没有空格,例如"C:/Test/db.accdb",那么它就像一个超级按钮,但是,如果路径中有空格,例如"C:/Test folder/db.accdb",那么...就没有多少了.知道为什么会这样吗?我的代码看起来像这样:(查询只是一个例子,您明白了这一点:)

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();

谢谢!

/尼克

推荐答案

将路径用单引号引起来

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

这篇关于Oledb,如果数据库路径中有空格,则崩溃... C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆