微软的Visual C#2010 - 添加数据到本地数据库 [英] Microsoft Visual C# 2010 - Adding Data to Local Database
问题描述
我从PHP过来和我有一个很难与存储信息到我的新创建的本地数据库。我使用Microsoft Visual C#2010帮助我学习和发展。
I'm coming over from PHP and am having a hard time with storing information into my newly created local database. I'm using Microsoft Visual C# 2010 to help me learn and develop.
我看很多人不喜欢数据集,会选择忽略它们放在一起。那如果我能够硬线到我的本地数据库是罚款。 (我没有使用所提供的服务器数据库的选择,因为我要把我的完整的产品到商业解决方案,这将要求用户存储自己的信息到存储他们的项目数据的本地数据库。
I'm reading that many people do not like datasets and would opt to ignore them all together. That is fine if I am able to hard-wire into my local database. (I did not use the server database option provided because I'll turn my completed product into a commercial solution and this will require the users to store their information into a local database that stores their project data.
我做了我的展示窗口的形式和我的数据库的视频,我的知识到目前为止程度。也许你们能帮忙吗?的 http://screencast.com/t/x9Qt1NtOgo6X
I've made a video showing my windows form and my database, and the extent of my knowledge so far. Maybe you guys can help? http://screencast.com/t/x9Qt1NtOgo6X
推荐答案
据取决于你的质量要求,但在大多数情况下,我会强烈建议您使用实体框架或LINQ to SQL数据类。你会好得多......后者去作为一个开始......希望它帮助。
It depends on your requirments, but for most situations, I would highly recommend you use Entity Framework or Linq to Sql data classes. You'd be much better off... go with the latter as a start... hope it helps.
如果你想看到一个ORM可以多么容易:
If you want to see how easy an ORM can be:
- 在您的项目
- 右键单击选择Add New Item
- 选择的Linq到SQL数据类
- 当您添加它,你就会有一个空白.dbml文件
- 转到服务器资源管理器,并添加连接到SQL数据库
- 拖放任何你喜欢的表
-
开始使用实体是这样的:
- right-click on your project
- select Add New Item
- Choose Linq to Sql Data Classes
- When you've added it, you'll have a blank .dbml file
- Go to server explorer and add a connection to the sql db
- Drag and drop the tables wherever you like
Start using the entities like this:
使用(DataClasses1DataContext DB =新DataClasses1DataContext(数据源= localhost\sqlexpress;初始目录= myDBName;集成安全=真))
{
IEnumerable的citiesForUSA = db.Cities.Where(X => x.Country.Name ==美国);
using (DataClasses1DataContext db = new DataClasses1DataContext("Data Source=localhost\sqlexpress; Initial Catalog=myDBName; Integrated Security=true")) { IEnumerable citiesForUSA = db.Cities.Where(x => x.Country.Name == "United States");
City city = new City();
city.Name = "Metropolis";
//etc
db.Cities.InsertOnSubmit(city);
db.SubmitChanges(); // <-- INSERT INTO completed
//etc
}
祝你好运!
: - )
这篇关于微软的Visual C#2010 - 添加数据到本地数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!