我在更改数据库后尝试刷新GridControl。更改将保存在数据库中,但GridControl不会显示新数据。如何刷新网格并显示数据库中所做的更改? update方法中的MessageBox是检查方法是否已执行并且MessageBox弹出以便执行。
使用GridControl的部分类
public partial class incidentCategorySearchControl : UserControl
{
public static incidentCategorySearchControl Instance { get; set; }
public incidentCategorySearchControl()
{
InitializeComponent();
Instance = this;
// This line of code is generated by Data Source Configuration Wizard
incIncidentCategoryTableAdapter1.Fill(reinvenT_QualityDataSet1.IncIncidentCategory);
}
public void updateGridControl()
{
MessageBox.Show("..........." );
//categoryGridControl.RefreshDataSource();
incIncidentCategoryTableAdapter1.Fill(reinvenT_QualityDataSet1.IncIncidentCategory);
}
}
调用GridControl更新方法的类的一部分:
private void saveCategoryChangeButton_Click(object sender, EventArgs e)
{
if (incidentCategoryDescTextBox.Text.Trim().Length == 0)
{
MessageBox.Show("Opslaan mislukt controleer a.u.b. of alle verplichte velden juist zijn ingevuld");
}
else
{
try
{
using (SqlConnection con = new SqlConnection(SqlServerConnection.sqlConnection.ConnectionString))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("UPDATE IncIncidentCategory SET IncIncidentCatDescription = @categoryDescription WHERE IncIncidentCategory = @categoryId", con))
{
IncidentCategory incidentCategoryUpdate = new IncidentCategory(Convert.ToInt32(incidentCategoryTextBox.Text), incidentCategoryDescTextBox.Text);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@categoryId", incidentCategoryUpdate._categoryId);
cmd.Parameters.AddWithValue("@categoryDescription", incidentCategoryUpdate._description);
cmd.ExecuteNonQuery();
MessageBox.Show("Wijzigingen opgeslagen");
}
}
incidentTypeChange.Instance.refreshCategorySearchBox();
incidentTypeMaintenance.Instance.refreshCategorySearchBox();
incidentCategorySearchControl.Instance.updateGridControl(); // update doesn't work
//var control = new incidentCategorySearchControl();
//control.updateDataGridView();
}
catch
{
MessageBox.Show("Voer voor beide velden geldige waarden in a.u.b.");
}
}