form_load问题,使用会话变量和文本框更新详细信息

时间:2011-08-15 19:05:14

标签: asp.net vb.net sql-server-2008-r2

我正在尝试允许用户在使用vb登录asp网站后更新其详细信息。使用form_load中的会话变量使用用户详细信息填充文本框。文本框应该是可编辑的,但出于某种原因,在单击提交按钮时不会注册更改。

对于同样的问题Database not updating after UPDATE SQL statement in ASP.net,有一个类似的问题从未得到解答。

请有人可以提供建议

提前致谢

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Txt_Fname.Text = Session("First_Name")
    Txt_LName.Text = Session("Last_Name")
    Txt_ContactNumber.Text = Session("Cell_Number")
    Txt_Email.Text = Session("Email_Address")
End Sub

Protected Sub Cmd_Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Cmd_Submit.Click



    Command.Connection = Connection
    Command.CommandText = "UPDATE dbo.User_Account Set First_Name = @First_Name, Last_Name = @Last_Name, Cell_Number = @Cell_Number, Email_Address = @Email_Address where Overall_ID = @Overall_ID"
    Command.Parameters.AddWithValue("@First_Name", Txt_Fname.Text)
    Command.Parameters.AddWithValue("@Last_Name", Txt_LName.Text)
    Command.Parameters.AddWithValue("@Cell_Number", Txt_ContactNumber.Text)
    Command.Parameters.AddWithValue("@Email_Address", Txt_Email.Text)
    Command.Parameters.AddWithValue("@Overall_ID", Session("ID"))

    Connection.Open()
    Command.ExecuteNonQuery()
    Connection.Close()

    Response.Redirect("MyAccount.aspx")
End Sub

1 个答案:

答案 0 :(得分:1)

如果不是page_ispostback,请在page_load中添加代码。

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If (Not Page.IsPostBack) then
        Txt_Fname.Text = Session("First_Name")
        Txt_LName.Text = Session("Last_Name")
        Txt_ContactNumber.Text = Session("Cell_Number")
        Txt_Email.Text = Session("Email_Address")
   End If
End Sub