当我点击更新时出于某种原因使用下面的代码时,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
答案 0 :(得分:3)
检查您的Page_Load
功能。
您是否正在PostBack
上执行某项操作以将文本框值设置为其他内容?
如果您要绑定数据,请确保在Not IsPostback
If Not IsPostBack
BindData()