Reputation: 173
I have created a simple table inside Nortwind db.I am trying to retrieve all data using datagridview .I think missed out something because nothing displays in datagridview.There is no exception and error massages just doesnt work
public void getData()
{
SqlConnection con = new SqlConnection(cnn);
DataSet ds = new DataSet();
cmd = new SqlCommand("Select * from info",con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(ds);
dataGridView1.DataSource = ds;
}
Upvotes: 1
Views: 1151
Reputation: 28642
You need to specify which table the DataGridView should show. Try following code snippet.
dataGridView1.DataSource = ds.Tables[0];
Upvotes: 3
Reputation: 2550
Use a DataTable
instead of a DataSet
Otherwise, you need to specify which table the DataGridView
should show.
Upvotes: 3