删除窗体中的数据而不关闭窗体 [英] Remove data in windows form without closing form
本文介绍了删除窗体中的数据而不关闭窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我以win形式删除数据库记录时遇到问题。成功删除记录后,它会在表单中显示,除非我关闭表单并重新加载它。在C#中是否有任何方法可以刷新表而无需重新启动表单?
private < span class =code-keyword> void cmddelete_Click( object sender,EventArgs e)
{
SqlConnection conn = new SqlConnection( @ 数据源= MANISH-PC\SQLEXPRESS ;初始目录=休假管理;综合安全性=真;汇总=错误);
conn.Open();
SqlCommand command = new SqlCommand( delete来自Emp_Details,其中id = @ id,conn);
command.Parameters.AddWithValue( id,txtempid.Text);
SqlDataAdapter adp = new SqlDataAdapter(command);
command.ExecuteNonQuery();
MessageBox.Show( 已成功删除);
Refresh();
conn.Close();
}
解决方案
你好,
我认为无需重新加载表单。只需通过选择
查询重新加载表。
嗨大师,
最好你写一个选择查询在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");
like
DataTable 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.
这篇关于删除窗体中的数据而不关闭窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文