简体   繁体   中英

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;
}

Use a DataTable instead of a DataSet

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

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

dataGridView1.DataSource = ds.Tables[0];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM