Hello everyone, i have the code below, it works fine but whenever i insert a student number that does not exist in the table, the rest of the textboxes will keep displaying data from the previous existing entry. This happens even when the i delete everything in the student number textbox.
how can i change it such that the rest of the textboxes are cleared in case the student number textbox is blank or contains a student number that does not exist in the database?
Thanks in advance.
Dim mycommand As SqlCommand = New SqlCommand() Dim datareader As SqlDataReader = Nothing myconnection.Open() Dim query As String query = " select StudentNo,Fullname,Year,Term,Class from StudentRegistration where StudentNo = '" & TxtStudentNo.Text & "' and (class = 'Senior 5A' or Class ='Senior 5S' or Class='Senior 6A' or class='Senior1 6S')" mycommand = New SqlCommand(query, myconnection) datareader = mycommand.ExecuteReader() While datareader.Read If datareader IsNot Nothing Then ' TxtStudentNo.Text = datareader.Item("StudentNo") TxtName.Text = datareader.Item("FullName") TxtYear.Text = datareader.Item("Year") TxtTerm.Text = datareader.Item("Term") TxtClass.Text = datareader.Item("Class") End If End While myconnection.Close() ' Catch ex As Exception 'MessageBox.Show(ex.Message) ' End Try`