Dear All;
I have a form contain with two TextBox control and one ComboBox. There are StaffCode(txtStaffCode),StaffName(txtStaffName),Gender(cboGender). After I insert data into table, I want to retrive it back by using Reader method. The code I had done as below:
Private Sub btnSearch_Click(-----)
dim cnn as new SqlClient.SqlConnection
dim cmd as new SqlClient.SqlCommand
dim dr as SqlClient.SqlDataAdapter
cmd=SqlClient.SqlCommand("SELECT StaffCode,StaffName,Gender FROM Staff WHERE StaffCode='" & Me.txtStaffCode & "'", cnn)
dr=cmd.ExecuteReader()
While dr.Read
If Me.txtStaffCode=dr.Item("StaffCode") Then
Me.txtStaffName.Text=dr.Item("StaffName")
me.cboGender.Text=dr.Item("Gender")
Else
'Here is the code I need to check.
'record with the text enter (staffcode)
'If it doesn't match, I want to show message
MessageBox.Show("No record found.","Not Found")
End IF
End While
dr.Close
cmd.Dispose
End Sub
Anyone can help me please,
Thank!