2

I've created an application (using c# winforms) in which I'm managing item sheets such books, music and movie dvds, games, etc. Those sheets contain basic information such title, synopsis, author, etc. There are even images (full-size + thumbnail).

So now I'm entering the stage of development where I need to save all the changes and load them again when I re-open the application. It's the first time I'm doing this kind of operation so I'm unsure of the best ways to do this.

So how do we save/load a database in a C# winform application? Are there best or faster methods than others?

Any link to tutorials would be greatly appreciated, I haven't found any valuable ones on my own, or the ones I've found dealt with Web applications.

Thank you!

4

4 回答 4

0

entity framework is probably your easiest choice. here is a tutorial:

http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx

于 2013-01-13T01:44:55.463 回答
0

Microsoft Entity Framework is the way to go.

I'd suggest to pay close attention to CodeFirst feature of EF because you have an application but don't have a DB yet. Here is Tutorial: Code First with EF 4.1

于 2013-01-13T01:45:05.180 回答
0

您可以在 Windows 窗体应用程序中使用“SQL 精简版”(我称之为本地 SQL)。因此,您无需连接到其他 DBMS 即可轻松加载/保存数据库。 http://www.microsoft.com/sql/editions/compact/default.mspx

于 2013-01-13T01:47:11.293 回答
0

将数据库数据加载到 Winforms 应用程序中

如果您不希望使用实体框架(例如在性能关键的情况下),则直接使用 ADO.NetSystem.Data.SqlClient 是另一种方法。此方法假定您使用的是Microsoft SQL Server

该方法可以这样调用:GetSqlData("Select * from myTable").

public static DataTable GetSqlData(string sql)
{
    // get Connectionstring from app.config 
    string connStr = System.Configuration.ConfigurationManager.AppSettings["YourConnection"];
    using (SqlConnection myConnection = new SqlConnection(connStr))
    {
        myConnection.Open();
        DataTable dt = new DataTable();
        using (var command = new SqlCommand())
        {
            command.Connection = myConnection;
            command.CommandText = sql;
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);                                        
            dt.Load(reader);
        }
        return dt;
    }            
}// End of GetSqlData

关于教程

由于来自微软的名为 windowsclient.net 的伟大网站(包含大量用户输入和官方视频)已经消失(1、2 ,您可以通过谷歌搜索beth massi forms over data 视频系列或只是form over data,您会发现剩下的来自 windowsclient.net 网站。

于 2013-02-17T17:27:30.527 回答