tags:

views:

93

answers:

2

Hello everyone,

im new with wpf and want to make a small Application with the embedded (local) database in WPF. Im using VS08, ->add new file -> local Database, so far so good. I also can add a table (test table called Person with Name and Age), this works good. 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). Need some code or step by step tut. :D

+1  A: 

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.

Justin Niessner
"[...]I would look into better ways to handle data management and binding like the MVVM pattern."+1 for this comment. testerws, please do heed Justin's advice and modify the application to use data binding as soon as you get it working. You will save yourself from a world of pain!
bufferz
A: 

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.

Guy Starbuck