user2583511
user2583511

Reputation: 173

Datagridview does not show data

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

Answers (2)

santosh singh
santosh singh

Reputation: 28642

You need to specify which table the DataGridView should show. Try following code snippet.

dataGridView1.DataSource = ds.Tables[0];

Upvotes: 3

banging
banging

Reputation: 2550

Use a DataTable instead of a DataSet

Otherwise, you need to specify which table the DataGridView should show.

Upvotes: 3

Related Questions