[英]I've created a database table using Visual Studio for my C# program. Now what?
I'm very new to C#, so please forgive me if I've overlooked something here. 我是C#的新手,所以如果我忽略了这里的内容,请原谅我。 I've created a database using Visual Studio (add new item > service-based database) called LoadForecast.mdf. 我已经使用Visual Studio(添加新项>基于服务的数据库)创建了一个名为LoadForecast.mdf的数据库。 I then created a table called ForecastsDB and added some fields. 然后,我创建了一个名为ForecastsDB的表,并添加了一些字段。 My main question is this: I've created a console application with the intention of writing some data to the newly created database. 我的主要问题是:我创建了一个控制台应用程序,旨在将一些数据写入到新创建的数据库中。 I've added LoadForecast.mdf as a data source for my program, but is there anything else I should do? 我已经将LoadForecast.mdf添加为程序的数据源,但是还有什么我应该做的吗? I saw an example where the next step was adding a "data diagram", but this was for a visual application, not a console application. 我看到了一个示例,其中下一步是添加“数据图”,但这是针对可视应用程序而不是控制台应用程序的。 Do I still need to diagram the database for my console app? 我还需要为控制台应用程序绘制数据库图吗? I just want to be able to write new records out to my database table and wasn't sure if there were any other things I needed to do for the VS environment to be "aware" of my database. 我只是希望能够将新记录写到数据库表中,并且不确定是否需要做其他事情才能使VS环境“了解”我的数据库。 Thanks for any advise! 感谢您的任何建议!
Well, it depends on what data access technology you want to use. 好吧,这取决于您要使用哪种数据访问技术。 You can use straight SqlClient, you can use untyped data sets, you can use strongly typed data sets, you can use LINQ to SQL, you can use Entity Framework. 您可以使用直接的SqlClient,可以使用无类型的数据集,可以使用强类型的数据集,可以使用LINQ to SQL,可以使用实体框架。
If you're not sure, then probably the most fun would be LINQ to SQL, so I recommend you follow a tutorial first and then come back to your app. 如果不确定,那么最有趣的可能就是LINQ to SQL,所以我建议您先阅读教程,然后再返回您的应用程序。 Eg. 例如。 ScottGu's LINQ to SQL (Part 4 - Updating our Database) , or MSDN's How to: Insert Rows Into the Database . ScottGu的LINQ to SQL(第4部分-更新我们的数据库) ,或MSDN的How to:在数据库中插入行 。
There are also video guides, like VS2008 Training Kit: Using LINQ with Relational Data or MSDN Webcast: Using LINQ with Relational Data (Level 100) . 也有视频指南,例如VS2008培训工具包:将LINQ与关系数据一起使用或MSDN网络广播:将LINQ与关系数据一起使用(级别100) 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.