问题
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