如何在解决方案中设置本地数据库的实际路径 [英] how to set realtive path for local db in the solution

查看:66
本文介绍了如何在解决方案中设置本地数据库的实际路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我需要在我的解决方案中设置数据库的相对路径,任何人都可以帮助我这个

Hi,

I need to set relative path for a db in my solution can any one help me in this

sqlConnection1.ConnectionString = "Data Source =c:\\MSProjectAddin\\MSProjectAddin\\MSProjectAddin\\Database1.sdf;Persist Security Info=False";

System.Data.SqlServerCe.SqlCeCommand cmd = new System.Data.SqlServerCe.SqlCeCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "INSERT [Employee] (Fname) VALUES ('Tim')";
cmd.Connection = sqlConnection1;

sqlConnection1.Open();
cmd.ExecuteNonQuery();
sqlConnection1.Close();

推荐答案

相对于什么?你的应用程序启动路径?

如果是,那么使用

Application.StartupPath它是你的application.exe文件所在的路径。

then您可以使用应用程序启动路径为数据库创建绝对路径。
relative to what ? your application start up path ?
If yes then use
Application.StartupPath it is the path where your application.exe file exist.
then you can make absolute path for your Database using application startup path.


检查此链接我认为这将对您有所帮助



< a href =http://arcanecode.com/2007/04/10/creating-a-sql-server-compact-edition-database-using-visual-studio-server-explorer/> http:// arcanecode。 com / 2007/04/10 / creating-a-sql-server-compact-edition-database-using-visual-studio-server-explorer / [ ^ ]

http://stackoverflow.com/questions/2375118/how-to -open-sdf-files [ ^ ]
check this link i think this will help you

http://arcanecode.com/2007/04/10/creating-a-sql-server-compact-edition-database-using-visual-studio-server-explorer/[^]
http://stackoverflow.com/questions/2375118/how-to-open-sdf-files[^]


这篇关于如何在解决方案中设置本地数据库的实际路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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