【发布时间】:2015-06-23 09:54:22
【问题描述】:
我有我的表单“InsertClient”,我有按钮点击方法
public void Insert_Button_Click(object sender, EventArgs e)
{
MyClass.InsertNewClient(fullNametxt.Text, shortNametxt.Text);
fullNametxt.Clear();
shortNametxt.Clear();
fullNametxt.Focus();
GridView.Update();
GridView.Refresh();
}
我的班级收到这个:
public static void InsertNewClient (String fullName, String shortName)
{
SqlConnection conn = DBClass.ConnectionString.GetConnection();
SqlCommand cmd = new SqlCommand("MyStoredProcedure", conn);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@fullName", fullName);
cmd.Parameters.AddWithValue("@shortName", shortName);
int i = cmd.ExecuteNonQuery();
if (i == 0)
{
MessageBox.Show("Can't save data");
}
if (i > 0)
{
MessageBox.Show("Data saved!");
}
}
问题是,数据已保存,但 DataGridView 不会在每次 INSERT(单击按钮)后刷新。我必须关闭表单并重新打开它并显示刷新。
请帮忙,我希望在插入数据后刷新 DataGridView
【问题讨论】:
-
datagridview 绑定源 =?
-
展示你如何将数据加载到
datagridview -
@RobertA 如果您想发布解决问题的代码,您应该将其发布为答案,而不是评论。然后,如果有人阅读了这个问题并想知道您是如何解决的,他们可以直接阅读下面的内容,而不是在 cmets 中挖掘它。
标签: c# datagridview refresh