Hello All, I'm new and trying to learn WPF. What I'm trying to do is fairly simple and being a newbie, this question may sound dumb and probably why I couldn't find answer? (I've searched google and other forums including this one). The following is my code (again, fairly simple and straight forward):



Public DataAdapter as New sqlClient.sqlDataAdapter(sqlCommandstr,sqlConnectStr)

Public dbTable as new DataTable

First I define the sqlAdapter and a data table object, now,

DataAdapter.SelectCommand.CommandText="select * from Company" --> where Company is just a table with few fields

DataAdapter.fill(dbTable)

Ok, so now the dbTable object is filled with the data extracted form SQL Server's "Company" table. Now I will fill the "DataGrid1" WPF datagrid control that I simply drag and drop into the WPF window.

DataGrid1.ItemSource=dbTable.DefaultView

Simple enough! And now hit the "run" button and the grid will show all the data from table "Company" on the screen.

Now here the PROBLEM. When I try to populate the same table object "dbTable" with a different set of data from SQL Server by:

dbTable.reset()

DataAdapter.SelectCommand.CommandText="select * from Customer" --> where customer is another table in the database

DataAdapter.fill(dbTable)

Ok Now I've check the dbTable, I'm sure it is with new data in there and the old data of "company" table has been wiped clean.

But when I do:

DataGrid1.ItemsSource=dbTable.DefaultView

The DataGrid1 now show only the header of the old table (the company table) and with ZERO rows. Why is that? Why the Grid did not show the new "Customer" table?

I've tried many things that were suggested throughout the search (on both google and here), but no use.

I've tried to do Datagrid1.columns.clear(), Datagrid1.rows.clear() AND I've tried Datagrid1.itemssource=nothing or DataGrid1.items.Refresh(), NOTHING WORKS. The grid would either show the old header with no data or the grid will simply be wiped empty. So when the underlying data of the table object "dbTable" changes, how can I rebind the Grid to show the new dataset?

P.S. I have the AutoGenerateColumns set the true.

Thank you!