datagridview not showing its dataset.

K

kristian

Hi all

I have a datagridview, and I want it to show and enable editing of a
table in my mysql database.

I get the results from the sql-query into the dataset, and when I view
the dataset in the debuger with the dataset viewer, I can see that the
dataset is filled with my data, but the datagridview is all grey,
showing no columns and no data.

I cannot figure out what's wrong/missing.


string sqlString = "SELECT * FROM vehicle";

OdbcCommand cm = new OdbcCommand(sqlString, OdbcCon);
DataAdapter da = new OdbcDataAdapter(cm);
da.TableMappings.Add("Table", "vehicle");

DataSet ds = new DataSet("vehicle");
da.Fill(ds);
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = ds;
 
M

Marc Gravell

Just a thought : try giving the dgv a DataTable rather than the
DataSet, or specify the table name in the dgv's DataMember.

Marc
 
K

kristian

Marc said:
Just a thought : try giving the dgv a DataTable rather than the
DataSet, or specify the table name in the dgv's DataMember.

Marc

Thanks a bunch, a simple
dataGridView1.DataMember = "vehicle";
did the job.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top