WPF: How to connect to a sql ce 3.5 database with ADO.NET?
- by EV
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.