出于某种奇怪的原因,DataGridView 没有被数据源中的表填充。我不确定我做错了什么。数据集确实有一个表。
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);
}
只是向您展示第一个查询方法,其他方法相同:
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;
}
}
}
}
}
同样,正在提取数据,但由于某种原因,DataGridView 没有改变。它只是灰色的。