Oladotun Obileye

Oladotun Obileye

  • NA
  • 98
  • 17.9k

How to stop update database from updating all the records

May 24 2019 7:40 PM
Good day everyone. please i am working on a c# windows form and whenever i click on the update button it updates all the records instead of a particular record i.e all the record will be updated instead of only one record
 
  1. //SqlConnection con = new SqlConnection();  
  2. //con.ConnectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\odt\Documents\Loanapp.mdf;Integrated Security=True;Connect Timeout=30";  
  3. con.Open();  
  4. SqlCommand cmd = con.CreateCommand();  
  5. cmd.CommandType = CommandType.Text;  
  6. cmd.CommandText = "update Registrationform set Employementnumber=@empno,FullName=@fullname,Dateofbirth=@dob,Gender=@gen,Occupation=@occ,Maritalstatus=@ms,Email=@email,Department=@dept,Position=@post,HomeAddress=@haddress,Phonenumber=@pno,Nationality=@nation,Stateoforigin=@soo,image=@img where Id=@id ";  
  7. cmd.Parameters.AddWithValue("@id", ID);  
  8. cmd.Parameters.AddWithValue("@empno", txtempno.Text);  
  9. cmd.Parameters.AddWithValue("@fullname", txtfullname.Text);  
  10. cmd.Parameters.AddWithValue("@dob", dob.Value);  
  11. cmd.Parameters.AddWithValue("@gen", gender);  
  12. cmd.Parameters.AddWithValue("@occ", txtoccupation.Text);  
  13. cmd.Parameters.AddWithValue("@ms", txtmaritalstatus.GetItemText(txtmaritalstatus.SelectedItem));  
  14. cmd.Parameters.AddWithValue("@email", txtemail.Text);  
  15. cmd.Parameters.AddWithValue("@dept", txtdept.Text);  
  16. cmd.Parameters.AddWithValue("@post", txtpost.Text);  
  17. cmd.Parameters.AddWithValue("@haddress", txthaddress.Text);  
  18. cmd.Parameters.AddWithValue("@pno", txtpno.Text);  
  19. cmd.Parameters.AddWithValue("@nation", txtnation.Text);  
  20. cmd.Parameters.AddWithValue("@soo", txtorigin.Text);  
  21. cmd.Parameters.AddWithValue("@img", img); 

Answers (1)