Could any one plz tell, where am i going wrong. I am unable to popup msgbox if count=0. It will work only if i use
MsgBox(""). I am unable to understand how it has anything to do with msgbox("")

Private Sub txtstaffID_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtstaffID.TextChanged
Dim conn As SqlClient.SqlConnection
conn = New SqlClient.SqlConnection("Data Source= ***.**.**.**; Initial Catalog=abc; Persist Security Info=True; User ID=" & user & "; Password=" & password)
Dim da As SqlClient.SqlDataAdapter
Dim dt As New DataTable
If txtstaffID.Text.Contains("E?") Then
strParsedEMPL = txtstaffID.Text.Substring(5, 6)
txtstaffID.Text = "w" + strParsedEMPL
da = New SqlClient.SqlDataAdapter("select position FROM staff WHERE id = ('" + txtstaffID.Text + "')", conn)
If dt.Rows.Count = 1 Then
txtstaffID.ReadOnly = True
MsgBox("You are allowed to access ")
cmdNext.Enabled = True
ElseIf dt.Rows.Count = 0 Then
txtstaffID.ReadOnly = False
MsgBox("ID not found ")
cmdNext.Enabled = False
ElseIf dt.Rows.Count > 1 Then
txtstaffID.ReadOnly = False
MsgBox(" more than 2 found")
End If
End If
End Sub

Both IF and Elseif code executes but the problem is the msgbox won't popup in both the cases( i.e when IF executes and when Elseif executes) unless and untill i have a msgbox("") before da.Fill(dt)

Let me see if I can help you. have you tried using a select

Select dt.rows.count
case 1
Messagebox.Show("You allowed to Access")
case 0
Messagebox.show("Id not found")
case >1
Messagebox.show("More than 2 found")
end select

Not sure if this may help you, but I did not notice a conn.Open() statement in your code. Also, in VB I have found that using a DataReader is sometimes easier to implement and debug than DataAdapter.