I am using WPF data binding to a dataset to display the contents of a table.
The SELECT statement can return no records and the datatable will not get any metadata from this. Then the WPF DataGrid is minimised with no columns.
I know it is possible to specifically query the metadata of the table but I am checking if there is a shorthand method.
If the query is empty how do I still get the column information?
People like to see code so here it is
Currently I have:
<DataGrid AutoGenerateColumns="True" EnableRowVirtualization="True"
ItemsSource="{Binding Path=SelectedUserTable, Mode=TwoWay}" Name="userTablesContentGrid"
RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Stretch">
</DataGrid>
In my ViewModel. DisplayUserTable is called to load the SelectedUserTable property
public void DisplayUserTable(string tableName)
{
if (!UserTablesDataSet.Tables.Contains(tableName))
{
FillTable(tableName);
}
SelectedUserTable = UserTablesDataSet.Tables[tableName];
InvokePropertyChanged("SelectedUserTable");
}
private void FillTable(string tableName)
{
UserTablesDataAdapter.SelectCommand = new SqlCommand(string.Format("SELECT * FROM [{0}]", tableName), _conn);
UserTablesDataAdapter.Fill(UserTablesDataSet, tableName);
}
Issue the DataAdapter.FillSchema command.