DataSet包含数据时DataGridView不显示数据

时间:2015-02-27 09:29:11

标签: c# datagridview dataset dataadapter

在以下代码中,我可以看到我的DataSet已经填充了数据,但我的DataGridView没有显示任何内容:

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

0 个答案:

没有答案