如何在项目中添加数据库 [英] How to add database with in the project

查看:74
本文介绍了如何在项目中添加数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我完成了一个C#程序,它从数据库中读取了一些信息
但是我已经在程序中设置了数据库路径,但是当我将其构建为exe文件时,问题出在什么地方,我们必须保持数据库路径相同
所以我想我可以在解决方案中添加databse吗,所以任何人都可以给我示例代码.所使用的数据库是ms sqlserver 2008

here i have done a c# program and it reads some information from the database
but and i already set the database path in the program but what the problem is when i build it to an exe file we have to keep the path of database the same
so i think can i add databse with in the solution .so can any one give me the sample code.the database used is of ms sqlserver 2008

推荐答案

不需要路径:连接字符串就是到达数据库所需的全部.请参见此处 [ ^ ]可以使用(并适应)各种各样的连接字符串.
You don''t need the path: the connection string is all you need to get to the database. See here[^] for a large variety of connection strings you can use (and adapt).


用以下内容更改connectionString并将"Library"数据库名称替换为数据库名称:

字符串constr;
constr =数据源=.\\ SQLEXPRESS; database = Library; Persist Security Info = False; Integrated Security = True;";
Change your connectionString with the following and substitute "Library" database name with your database name:

string constr;
constr = "Data Source=.\\SQLEXPRESS;database=Library;Persist Security Info=False;Integrated Security=True;";


这篇关于如何在项目中添加数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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