I'm new with WPF and I want to make a small application with the embedded (local) database in WPF. I'm using VS08, --> add new file --> local Database.
I can also add a table (test table called Person with Name and Age). And now comes my problem, could anyone tell me how to make (select... insert) statements in codebehind, so that I could display them in a datagrid (from wpftoolkit).
This Article has all the code you need:
Data Binding in WPF ListView
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.
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.