更新时间:2023-12-06 16:10:22
你好,
我认为无需重新加载表单。只需通过选择
查询重新加载表。
嗨大师,
***你写一个选择查询在MessageBox.Show之后(已成功删除);
喜欢DataTable dt = ne DataTable():
SqlCommand命令= new SqlCommand( 从Emp_Details中选择*跨度>);
SqlDataAdapter adp = new SqlDataAdapter(command,conn);
adp.Fill(dt);
现在使用数据表dt中的数据。
u将获取除已删除的记录记录。
I am having a problem when i delete a database record in win form. After successfully deleting a record, it show in the form unless i close the form and reload it again. Is there any method in C# by which we can refresh the table without restarting the form?
private void cmddelete_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=MANISH-PC\SQLEXPRESS;Initial Catalog=Leavemanagement;Integrated Security=True;Pooling=False");
conn.Open();
SqlCommand command = new SqlCommand("delete from Emp_Details where id=@id",conn);
command.Parameters.AddWithValue("id", txtempid.Text);
SqlDataAdapter adp = new SqlDataAdapter(command);
command.ExecuteNonQuery();
MessageBox.Show("successfully Deleted");
Refresh();
conn.Close();
}
Hello ,
I think no need to reload the form . just reload the table by aSelect
query .
Hi guru,
Better you write a select query after MessageBox.Show("successfully Deleted");
likeDataTable dt=ne DataTable(): SqlCommand command = new SqlCommand("Select * from Emp_Details"); SqlDataAdapter adp = new SqlDataAdapter(command,conn); adp.Fill(dt);
Now use the data present in the datatable dt.
u will get the records except deleted record.