May 14, 2010 at 5:34 PM
Edited May 14, 2010 at 5:39 PM
Hello All, I'm new and trying to learn WPF. What I'm trying to do is fairly simple and probably being a newbie, this question may sound dumb. But I did search both here and google, still no answer. 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
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.
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:
DataAdapter.SelectCommand.CommandText="select * from Customer" --> where customer is another table in the database
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:
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 thing 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.