I have a local Microsoft SQL Server Compact 3.5 database (.sdf) in my WPF program.
In my datagrid, I see “old” data. Only if I click refresh in the Database Explorer in Visual Studio 2010, do I see the new inserted data.
How can you programmatically refresh the database connection?
To be clear:
On the load of my programm I put in data to the database with an SQL query like INSERT INTO clients VALUE (2, Peter, Smith)
Then I call een an tableAdapter.Fill(dataset.clients) and this.DataContext = dataset.clients.DefaultView;
I expect the dataTable in the dataSet will be filled with data which I inserted a second ago in the database. And after that the data is shows in the dataGrid. But that don’t happen. I only see the inserted data if I stop debugging and press (in design-time) the refresh button of the Database Explorer en then debug again…
If you’re trying to bind from your SQL CE database, consider implementing code that uses data binding. This will ensure your data is always ‘fresh’ on your grid. Here’s some sample code on Data Binding in WPF.
It sounds as if you’re expecting to see ‘fresh’ data in your grid at design-time. “click refresh in Database Explorer” suggests that the design surface you’re viewing.
If not, then your statements around Database Explorer and anything at run-time don’t make sense. Your grid should be repopulated/databound on an event that makes sense (form load, user clicking button, user inserting a row). The user doesn’t/shouldn’t know about Database Explorer. The proper way to have your grid show the latest data is
myGrid.DataBind();If so, may I suggest that it shouldn’t/doesn’t really matter, as the data shown on the grid is simply intended to be a ‘placeholder’. If you did want to see fresh data, then your only option is as you suggest: ‘refreshing’ via Database Explorer.
It’s very unclear on what you’re seeing or expecting. Suggest editing your question with your code, and some screenshots to illustrate.