For some odd reason, the DataGridView is not being populated with the table from the data source. I’m not sure what I’m doing wrong. The data set DOES have a table.
private void BtnViewUncommittedDataClick(object sender, EventArgs e)
{
if (rbtnNewBusiness.Checked)
{
try
{
UpdateGridForNewBusiness();
return;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
Logger.LogError(ex.Source, ex.TargetSite.ToString(), ex.Message);
Enabled = true;
return;
}
}
}
private void UpdateGridForNewBusiness()
{
dgvDetail.DataSource = Database.GetNewBusinessDetailJobData();
dgvSummary.DataSource = Database.GetNewBusinessSummaryJobData();
dgvDetailNYD.DataSource = Database.GetNewBusinessDetailJobDataNyd();
dgvSummaryNYD.DataSource = Database.GetNewBusinessSummaryJobDataNyd();
lblDetailRowCountlbl.Text = "";
lblDetailNYDRowCountlbl.Text = "";
lblSummaryRowCountlbl.Text = "";
lblSummaryNYDRowCountlbl.Text = "";
lblDetailRowCountlbl.Text = "New Business Detail - Row Count:";
lblDetailNYDRowCountlbl.Text = "New Business Detail NYD - Row Count:";
lblSummaryRowCountlbl.Text = "New Business Summary - Row Count:";
lblSummaryNYDRowCountlbl.Text = "New Business Summary NYD - Row Count:";
lblDetailRowCount.Text = dgvDetail.Rows.Count.ToString(CultureInfo.InvariantCulture);
lblSummaryRowCount.Text = dgvSummary.Rows.Count.ToString(CultureInfo.InvariantCulture);
lblDetailNYDRowCount.Text = dgvDetailNYD.Rows.Count.ToString(CultureInfo.InvariantCulture);
lblSummaryNYDRowCount.Text = dgvSummaryNYD.Rows.Count.ToString(CultureInfo.InvariantCulture);
}
Just showing you the first query method as the others are the same:
public static DataSet GetNewBusinessDetailJobData()
{
using (var conn = new SqlConnection(Settings.Default.ConnectionString))
{
using (var cmd = new SqlCommand("spGetNewBusinessDetailJobData", conn) {CommandType = CommandType.StoredProcedure})
{
conn.Open();
cmd.ExecuteNonQuery();
using (var da = new SqlDataAdapter(cmd))
{
using (var ds = new DataSet())
{
da.Fill(ds);
return ds;
}
}
}
}
}
Again, data IS being pulled but for some reason, the DataGridView does not change. It’s simply gray.
I figured out the issue.
I cannot set the DataSource of a DataGridView to be a DataSet. It has to be a DataTable.