2

当我在单击更新时出于某种原因使用下面的代码时,hospitaltextbox.text 没有在文本框中显示当前值?只是最初选择的值。知道为什么它没有读取文本框中当前的内容吗?

Dim reader As SqlDataReader = cmd.ExecuteReader()
        If (reader.Read()) Then

            HospitalTextBox.Text = reader(7)
            FirstNameTextBox.Text = reader(9)
            Session("ID") = reader(0)
        End If

Protected Sub cmdUpdate_Click(sender As Object, e As EventArgs) Handles cmdUpdate.Click
    Dim Test As String
    Test = FirstNameTextBox.Text
    Try
        Dim Con As SqlConnection
        Dim cmd As SqlCommand
        Con = New SqlConnection
        Con.ConnectionString = ""
        Con.Open()
        cmd = New SqlCommand
        cmd.Connection = Con
        cmd.CommandText = "UPDATE tbltest SET [Teaching Hospital Name] = @TeachingHospitalName, [Physician First Name] = @FirstName WHERE ID = @ID"
        cmd.Parameters.Add(New SqlParameter("@ID", (Session("ID"))))
        cmd.Parameters.Add(New SqlParameter("@TeachingHospitalName", HospitalTextBox.Text)) 'does not show text that was changed in the textbox?
        cmd.Parameters.Add(New SqlParameter("@FirstName", Test))
        cmd.ExecuteNonQuery()
        Con.Close()


    Catch ex As Exception

    End Try
End Sub
4

1 回答 1

3

检查你的Page_Load功能。

您是否正在PostBack将文本框值设置为其他值?

如果您要绑定数据,请确保在Not IsPostback

If Not IsPostBack
   BindData()
于 2013-07-25T15:55:05.933 回答