basically I have a form with 3 fields, ID, NAME and ADDRESS. What I want to do is after I enter my ID it will fetch the NAME and ADDRESS data from my access database.
I want it to fetch the data after I finish entering the ID, but the problem is its fetching the data every time I enter a letter or number.
If anyone know an easier way to do it let me know.
Public Class Form3
Private Sub TextBox1_textChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TabIndexChanged
Dim myCustomer As New Customer
myCustomer.cid = TextBox1.Text
myCustomer.getData(myCustomer.cid)
If myCustomer.RecExist Then
TextBox2.Text = myCustomer.CName
TextBox3.Text = myCustomer.addres
Else
MessageBox.Show("record not exist")
End If
End Sub
End Class
Assembly Class
Public Class Customer
Public cid As String
Public CName As String
Public City As String
Public Rating As String
Public orders As New ArrayList
Private hiddenexist As Boolean
Public ReadOnly Property RecExist() As Boolean
Get
RecExist = hiddenexist
End Get
End Property
Public Sub getData(ByVal SearchID As String)
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\mcwlse\Desktop\12\SalesDB.mdb"
Dim objConn As New OleDbConnection(strConn)
Dim strSQL As String = "select * from customer where cid = '" & SearchID & "'"
Dim objComm As New OleDbCommand(strSQL, objConn)
objConn.Open()
Dim objDataReader As OleDbDataReader
objDataReader = objComm.ExecuteReader()
If objDataReader.Read() = False Then
hiddenexist = False
MessageBox.Show("Record does not exist")
Else
hiddenexist = True
cid = objDataReader("cid")
CName = objDataReader("CName")
City = objDataReader("City")
Rating = objDataReader("Rating")
End If
objConn.Close()
End Sub