whats wrong with this code ? i want populate all users in datagridview1 but datagirdview showing nothing .
private void button4_Click( object sender, EventArgs e )
{
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = db.todosUsuario("select usuario from usuarios");
}
//DB class
public DataSet todosUsuario(string query)
{
DataSet dt= new DataSet();
try
{
MySqlConnection cnn = new MySqlConnection(MysqlConnect());
cnn.Open();
MySqlDataAdapter da = new MySqlDataAdapter(query, cnn);
da.Fill(dt,"Usuario");
cnn.Close();
}
catch(Exception ed)
{
MessageBox.Show(ed.ToString());
}
return dt;
}
You are binding the DataGridView to a DataSet.
In a dataset there are multiple tables so you need to specify which table should be shown in the DataGrid using the DataMember property. (Yes also when you have only one in the tables collection)
You could change the code binding to a single table