private void btndelete_Click(object sender, EventArgs e)
{
if (txtserch.Text == "")
{
MessageBox.Show("Enter Customer name to delete");
}
else
{
l1.conn();
SqlCommand cmd = new SqlCommand("delete from CUSTOMER where NAME='" + txtserch.Text + "'", l1.connection);
int a = cmd.ExecuteNonQuery();
if (a == 1)
{
MessageBox.Show("Deleted Sucessfully");
dataGridView1.Refresh();
dataGridView1.RefreshEdit();
dataGridView1.Update();
txtserch.Text = "";
}
else
{
MessageBox.Show("Customer Not Exist");
txtserch.Text = "";
}
}
}
答案 0 :(得分:1)
DataGridView.Refresh()
是图形刷新,而不是数据刷新。
将DatagridView重新绑定到源。
DataGridView dataGridView1 = new DataGridView();
dataGridView1.DataSource = source;
// Update Data in src1
dataGridView1.DataSource = null;
dataGridView1.DataSource = source;
答案 1 :(得分:0)
为了刷新你的网格重新绑定..
MyGridView.DataSource = ds;
MyGridView.DataBind();
此处 ds 是您向网格提供的数据源。
有关详细信息,请参阅此link
答案 2 :(得分:0)
如果您想在编辑/删除/更新操作后将数据绑定到Gridview,那么您要编写以下代码行
GridviewName.DataSource = ds;// retrieve the details and store in ds
GridViewName.DataBind();