I know this has been asked before several times but I am not able to get this.
I have a DataSet
and a DataGrid
. All I want to do is display the contents of the DataSet
in the DataGrid
.
I have written this code :
vConn = new OleDbConnection(ConnectionString);
vConn.Open();
vQuery = "Select * from Book";
DataSet vDs = new DataSet();
OleDbDataAdapter vAdap = new OleDbDataAdapter(vQuery, vConn);
vAdap.Fill(vDs,"Book");
GridData.DataContext = vDs.Tables["Book"];
vConn.Close();
But for some reason the data is not shown on DataGrid. I have tried setting AutoGenerateColumn to True/False. I also tried binding in xaml but it didn't work.
this should work:
GridData.ItemsSource = vDs.Tables["Book"].DefaultView;
or you can create your own DataView
:
GridData.ItemsSource = new DataView(vDs.Tables["Book"]);
DataTable.DefaultView
gives you DataView
which implements IEnumerable
and can be used as ItemsSource
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With