using(SqlConnection conn = new SqlConnection(connectionString))
{
// Rest of the code goes here.
// You no longer have to explicitly close the connection either.
}
You might want to modify the Database code a little though:
using(SqlConnection conn = new SqlConnection(connectionString))
{
// Rest of the code goes here.
// You no longer have to explicitly close the connection either.
}
Although, if your application is going to do anything even remotely complicated I would look into better ways to handle data management and binding like the MVVM pattern.
对于使用嵌入式数据库的小型应用程序,我倾向于使用 SQLMetal,它是 VS 附带的一个命令行工具,可以为 SQL CE 生成 LINQ to SQL 数据上下文。 此处是 www.hookedonlinq.com 上的一页使用概述。生成数据上下文并将类添加到项目中后,您可以使用 Linq to SQL 语法访问数据。
可使用 Visual Studio 命令提示符使用 SQLMetal 命令。
You could use straight ADO.net if you want to, there are lots of materials and reference for this.
For small apps that use an embedded database, I tend to use SQLMetal, which is a command-line tool that comes with VS that generates LINQ to SQL data context for SQL CE. Here is a one-page overview at www.hookedonlinq.com of usage. After generating the data context and adding the classes into your project, you can access data using Linq to SQL syntax.
The SQLMetal command is available using the Visual Studio command prompt.
发布评论
评论(2)
本文包含您需要的所有代码:
WPF ListView 中的数据绑定
不过,您可能想稍微修改一下数据库代码:
尽管如此,如果您的应用程序要做任何事情,即使是远程复杂的事情,我也会寻找更好的方法来处理数据管理和绑定,例如 MVVM 模式。
This Article has all the code you need:
Data Binding in WPF ListView
You might want to modify the Database code a little though:
Although, if your application is going to do anything even remotely complicated I would look into better ways to handle data management and binding like the MVVM pattern.
如果您愿意,可以直接使用 ADO.net,有很多这方面的材料和参考。
对于使用嵌入式数据库的小型应用程序,我倾向于使用 SQLMetal,它是 VS 附带的一个命令行工具,可以为 SQL CE 生成 LINQ to SQL 数据上下文。 此处是 www.hookedonlinq.com 上的一页使用概述。生成数据上下文并将类添加到项目中后,您可以使用 Linq to SQL 语法访问数据。
可使用 Visual Studio 命令提示符使用 SQLMetal 命令。
You could use straight ADO.net if you want to, there are lots of materials and reference for this.
For small apps that use an embedded database, I tend to use SQLMetal, which is a command-line tool that comes with VS that generates LINQ to SQL data context for SQL CE. Here is a one-page overview at www.hookedonlinq.com of usage. After generating the data context and adding the classes into your project, you can access data using Linq to SQL syntax.
The SQLMetal command is available using the Visual Studio command prompt.