WPF: How to connect to a sql ce 3.5 database with ADO.NET?

Posted by EV on Stack Overflow See other posts from Stack Overflow or by EV
Published on 2010-04-04T18:54:36Z Indexed on 2010/04/04 19:03 UTC
Read the original article Hit count: 329

Filed under:
|
|

Hi, I'm trying to write an application that has two DataGrids - the first one displays customers and the second one selected customer's records. I have generated the ADO.NET Entity Model and the connection property are set in App.config file. Now I want to populate the datagrids with the data from sql ce 3.5 database which does not support LINQ-TO-SQL.

I used this code for the first datagrid in code behind:

CompanyDBEntities db;

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        db  = new CompanyDBEntities();
        ObjectQuery<Employees> departmentQuery =
            db.Employees;

        try
        {
            // lpgrid is the name of the first datagrid

            this.lpgrid.ItemsSource = departmentQuery;

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

However, the datagrid is empty although there are records in a database. It would also be better to use it in MVVM pattern but I'm not sure how does the ado.net and MVVM work together and if it is even possible to use them like that.

Could anyone help? Thanks in advance.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about ADO.NET