Answer the question
In order to leave comments, you need to log in
How to retrieve the correct data from the database?
I connected the database to the application, brought something to the data grid.
"binding" to datagrid headers does not work. (the binding is in quotes, because it's not a binding).
Three additional columns are created, how to remove them?
Connection and output:
string MyConString = "server=localhost;user=root;database=food;password=root;";
string sql = "SELECT name, amount, date FROM Products";
using (MySqlConnection connection = new MySqlConnection(MyConString))
{
try
{
connection.Open();
using (MySqlCommand cmdSel = new MySqlCommand(sql, connection))
{
DataTable dataTable = new DataTable();
MySqlDataAdapter adapter = new MySqlDataAdapter(cmdSel);
adapter.Fill(dataTable);
productsgrid.ItemsSource = dataTable.DefaultView;
}
connection.Close();
}
catch(Exception)
{
MessageBox.Show("Something wrong");
}
}
Answer the question
In order to leave comments, you need to log in
It was necessary to set AutoGenerateColumns to False (as Foggy Finder said ) and then set the binding for the columns -Binding="{Binding Path='value'}"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question