当我在单击更新时出于某种原因使用下面的代码时,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