Linking text boxes to a database without being databound
-
I have a program that what I want to happen is, when you type something into "txtEmployee" it will search the employeeID field in employee table and a message should appear saying "This employee does not exist" or show their details in "txtAddress" (Address 1 in table) "TxtPostcode" (Postcode in table) Now what I don't want to happen is for the textboxes to be databound to the table fields, as I only want the textboxes to connect to the database table fields whenever I type something in. How would I do all this? Thanks in advance
In the end we're all just the same
-
I have a program that what I want to happen is, when you type something into "txtEmployee" it will search the employeeID field in employee table and a message should appear saying "This employee does not exist" or show their details in "txtAddress" (Address 1 in table) "TxtPostcode" (Postcode in table) Now what I don't want to happen is for the textboxes to be databound to the table fields, as I only want the textboxes to connect to the database table fields whenever I type something in. How would I do all this? Thanks in advance
In the end we're all just the same
You should do something like that: Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged Dim txt, SQL As String txt = Me.TextBox1.Text.Trim 'you should connect to DB only if lenght is greater for example 3 If txt.Length > 3 Then SQL = "select EMP_ID from EMP_TABLE where EMP_ID like '" & txt & "%'" Dim dt As DataTable 'call some your function that returns datatable or. write code here 'dt = getDatatable(SQL,"SOMETABLE") If dt.Rows.Count = 0 Then MsgBox("This employee does not exist") End If End If End Sub