For WPF use DataGrid instead of DataGridView
. The following will fill a DataGrid
from a SQL Server database.
SqlConnection SqlConnect = new SqlConnection(connectionstring);
SqlConnect.Open();
SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM dbo.Courses", SqlConnect);
DataSet myDataSet = new DataSet();
adapter.Fill(myDataSet, "Courses");
Grid.DataContext = myDataSet;
Grid.ItemsSource = myDataSet.Tables[0].DefaultView;
You can use OleDbConnection
instead of SqlConnection
and OleDbDataAdapter
instead of SqlDataAdapter
.
Filtering the data is much more complicated.