DataGridView not displaying data while DataSet contains the data

只愿长相守 提交于 2019-12-11 13:05:45

问题


In the following code, I can see that my DataSet is already filled with data but my DataGridView displays nothing:

string sql = "SELECT * FROM MyTable";
try
{
    ds = new DataSet("Downloads");
    using (IDbConnection conn = dataFactory.GetDbConnection())
    {
        conn.ConnectionString = Common.Conf.ConnectionString;
        da = dataFactory.GetDbDataAdapter();
        IDbCommand cmd = dataFactory.GetDbCommand();
        cmd.CommandText = sql;
        cmd.Connection = conn;
        da.SelectCommand = cmd;                       
        conn.Open();
        da.Fill(ds);
        conn.Close();
    }
    dgv.DataSource = ds;                
    dgv.DataMember = "Downloads";
    if (dgv.Rows == null || dgv.Rows.Count == 0)
        lblDownloads.Text = "No download history found";
}
catch (Exception ex)
{
    return false;
}

来源:https://stackoverflow.com/questions/28761572/datagridview-not-displaying-data-while-dataset-contains-the-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!