为什么这个更新只工作一次?

时间:2022-10-02 06:50:42
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?

它只更新我的数据库一次。当我再次尝试更新时,它没有取值。为什么?

1 个解决方案

#1


1  

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.

如果数据库(.mdf/.sdf)是解决方案的一部分,那么在每次从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.

在您的PC上安装数据库,而不是向解决方案添加mdf/sdf文件。

This installed database will keep the data you added/modified across debug sessions.

这个已安装的数据库将保留您在调试会话中添加/修改的数据。

#1


1  

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.

如果数据库(.mdf/.sdf)是解决方案的一部分,那么在每次从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.

在您的PC上安装数据库,而不是向解决方案添加mdf/sdf文件。

This installed database will keep the data you added/modified across debug sessions.

这个已安装的数据库将保留您在调试会话中添加/修改的数据。