4
Answers

how to update the data in asp.net using C#

Shubham Agrawal

Shubham Agrawal

7y
203
1
i can't update data with tihs Code. So can Anyone suggest me as soon as possible. 
  1. string CN = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;  
  2. using (SqlConnection cn = new SqlConnection(CN))  
  3. {  
  4. cn.Open();  
  5. string s = "update Users set Username=@Username,Email=@Email,Password =@Password,City =@City,ContactNo =@ContactNo where ( Id =@Id)";  
  6. SqlCommand cmd = new SqlCommand(s, cn);  
  7. cmd.Parameters.AddWithValue("@Username", textbox1.Text);  
  8. cmd.Parameters.AddWithValue("@Email", textbox2.Text);  
  9. cmd.Parameters.AddWithValue("@Password", textbox3.Text);  
  10. cmd.Parameters.AddWithValue("@City", textbox4.Text);  
  11. cmd.Parameters.AddWithValue("@ContactNo", textbox5.Text);  
  12. cmd.Parameters.AddWithValue("@Id", textbox6.Text);  
  13. cmd.ExecuteNonQuery();  
  14. Response.Write("Your data SuccessFully Updated");  

Answers (4)