Reputation: 21
SqlCommand mcd = new SqlCommand("update Customer_Info set Name=@name,Gender=@gender,DateOfBirth=@DOB,EmailID=@email,Mob_No=@mob,Landline_No=@land,Address=@address,State=@state,City=@city,PinCode=@pincod,Last_Login=@logi where UserName=@user1", con);
mcd.Parameters.AddWithValue("@name",TextBox1.Text);
mcd.Parameters.AddWithValue("@gender",gender);
mcd.Parameters.AddWithValue("@DOB",TextBox2.Text);
mcd.Parameters.AddWithValue("@email",TextBox3.Text);
mcd.Parameters.AddWithValue("@mob", TextBox4.Text);
mcd.Parameters.AddWithValue("@land", TextBox5.Text);
mcd.Parameters.AddWithValue("@address", TextBox6.Text);
mcd.Parameters.AddWithValue("@state", TextBox7.Text);
mcd.Parameters.AddWithValue("@city", TextBox8.Text);
mcd.Parameters.AddWithValue("@pincod", TextBox9.Text);
mcd.Parameters.AddWithValue("@logi",datelog);
mcd.Parameters.AddWithValue("@user1",lblUserName.Text.Trim());
int d = mcd.ExecuteNonQuery();
if (d > 0)
{
Response.Write("<script>alert('updated ....')</script>");
It's only updating my database once. When I try to update again, it's not taking the value. Why?
Upvotes: 2
Views: 112
Reputation: 50682
If the database (.mdf/.sdf) is part of the solution it will be re-deployed (and overwite the modified database) every time you start the application from within Visual Studio.
Either try to update multiple times within the same debug session or do not redeploy the database every single time.
EDIT
To fix it if this is what is wrong:
Install the database on your PC instead of adding an mdf/sdf file to the solution.
This installed database will keep the data you added/modified across debug sessions.
Upvotes: 1