Click here to Skip to main content
16,009,114 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
C#
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();
       }
Posted
Updated 26-Apr-14 11:00am
v2
Comments
Meysam Toluie 26-Apr-14 4:18am    
What's the use of
SqlDataAdapter adp = new SqlDataAdapter(command);

Hello ,

I think no need to reload the form . just reload the table by a Select query .
 
Share this answer
 
v2
Hi guru,
Better you write a select query after MessageBox.Show("successfully Deleted");
like
C#
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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900