连接字符串问题 [英] connections string issue

查看:73
本文介绍了连接字符串问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我在C#中有一个窗口应用程序,带有MS-Access数据库.我给出了以下代码来连接我的数据库:

Hi All,
I have a window application in C# , with MS-Access database.I have given the following code to connect with my database:

string str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\mydb.mdb";
            OleDbConnection conn = new OleDbConnection((str));


运行良好.但是我只想提供数据库文件名而不是数据源中的整个路径.

谢谢.


Its running fine. But I want to give only the database file name not the whole path in Data Source.

Thanks.

推荐答案

将数据库文件保存在应用程序的Debug文件夹中,然后
将您的连接字符串更改为

keep ur database file in Debug folder of your application then
change ur connectionstring as

string strFilepath = ".\\mydb.mdb";





string str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+strFilepath+"";
            
OleDbConnection conn = new OleDbConnection((str));


你好udaysama,

您可以将数据库文件移动到项目文件夹.

希望对您有所帮助,
:)
Hi udaysama,

You can move your database file to your project folder.

I hope this help,
:)


对于每个示例,我都可以在 http://www.connectionstrings.com/access [^ ]

它们似乎都使用完整路径.
For every example I can see on http://www.connectionstrings.com/access[^]

They all seem to use a full path.


这篇关于连接字符串问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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