Guest User

Untitled

a guest
May 21st, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. SqlConnection con = new SqlConnection();
  2. con.ConnectionString = ConfigurationManager.ConnectionStrings["studentCS"].ConnectionString;
  3.  
  4. string name = tb_name.Text;
  5. string adminno = tb_admno.Text;
  6. string telephone = tb_telno.Text;
  7. string height = tb_height.Text;
  8.  
  9. string sql = "Update studentTable Set studName=@pStudName, telephone=@pTelephone, heightCM=@pHeightCM";
  10. sql = sql + " where adminNo= '" + ddl_adminno.SelectedValue + "'";
  11.  
  12. SqlCommand cmd = new SqlCommand(sql, con);
  13.  
  14. cmd.Parameters.AddWithValue("@pStudName", tb_name.Text);
  15. cmd.Parameters.AddWithValue("@pAdminNo", tb_admno.Text);
  16. cmd.Parameters.AddWithValue("@pTelephone", tb_telno.Text);
  17. cmd.Parameters.AddWithValue("@pHeightCM", tb_height.Text);
  18.  
  19. try
  20. {
  21. con.Open();
  22. cmd.ExecuteNonQuery();
  23. lb_msg.Text = "Record updated successfully";
  24. }
  25. catch (Exception ex)
  26. {
  27. lb_msg.Text = "Problem encountered:" + ex.Message;
  28. }
  29. finally
  30. {
  31. con.Close();
  32. con.Dispose();
  33. cmd.Dispose();
  34. }
Add Comment
Please, Sign In to add comment