Hi guys,
I have just started learning C# WPF and I am trying to fill a datagrid with the contents of a mysql table.
The code I have for a button to do this is:
When I run the app, I connect successfully but the datagrid does not show the contents of the selected table.
What am I doing wrong, is the datagrid even the correct component for this?
Thanks
I have just started learning C# WPF and I am trying to fill a datagrid with the contents of a mysql table.
The code I have for a button to do this is:
Code:
private void button1_Click(object sender, RoutedEventArgs e)
{
string MyConString =
"SERVER=localhost;" +
"DATABASE=vs;" +
"UID=user;" +
"PASSWORD=pass;";
MySqlConnection myCon = new MySqlConnection(MyConString);
try
{
myCon.Open();
MessageBox.Show("MySQL connection open");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
string sql = "select * from human";
MySqlCommand myCmd = new MySqlCommand(sql, myCon);
MySqlDataReader myReader = myCmd.ExecuteReader();
dataGrid1.ItemsSource = myReader;
}
When I run the app, I connect successfully but the datagrid does not show the contents of the selected table.
What am I doing wrong, is the datagrid even the correct component for this?
Thanks