[英]Data is inserted in this table but the datagridview shows as null values
[英]After inserting/deleting datagridview not shows the inserted item
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 = "";
}
}
}
DataGridView.Refresh()
是圖形刷新,而不是數據刷新。 將您的DatagridView重新綁定到源。
DataGridView dataGridView1 = new DataGridView();
dataGridView1.DataSource = source;
// Update Data in src1
dataGridView1.DataSource = null;
dataGridView1.DataSource = source;
如果要在編輯/刪除/更新操作后將數據綁定到Gridview,則要在下面的代碼行中編寫
GridviewName.DataSource = ds;// retrieve the details and store in ds
GridViewName.DataBind();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.