private void btnloaddata_Click(object sender, RoutedEventArgs e) { try { // Call the function from the View Model, then the View Model will call the // Model to execute these codes below and return the results here dataGridCustomers.DataContext = vm.CallDisplayProdinNeed(); } catch (MySqlException ex) { MessageBox.Show(ex.ToString()); } finally { conn.Close(); } }