اخي الكريم :
وضعت لك تعديل على مثالك . ولكن قاعدة البيانات المرفقه لم تعمل معي . لذا في الـ Module قم بكتابة جملة الاتصال ..

الكود كالتالي :
في Module اضف
وفي Form1 اضف
وضعت لك تعديل على مثالك . ولكن قاعدة البيانات المرفقه لم تعمل معي . لذا في الـ Module قم بكتابة جملة الاتصال ..

الكود كالتالي :
في Module اضف
PHP كود :
Module Module1
Public connDB As New SqlClient.SqlConnection
Dim constring As String = "جملة الاتصال Data Source ... ~~~"
Public Function comDB() As SqlClient.SqlCommand
Dim bb As New SqlClient.SqlCommand
With bb
connDB.Close()
If connDB.State <> ConnectionState.Open Then
connDB.ConnectionString = constring
Try
connDB.Open()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "")
Return bb
Exit Function
End Try
End If
.Connection = connDB
.CommandType = CommandType.Text
.CommandTimeout = 0
End With
Return bb
End Function
Public Sub closeDB()
If connDB.State <> ConnectionState.Closed Then connDB.Close()
End Sub
Public Sub FillList(Table As String, Field As String, txt As TextBox)
Dim col As New AutoCompleteStringCollection
With comDB()
.CommandText = "SELECT DISTINCT " & Field & " FROM " & Table
Using rdDB = .ExecuteReader
If rdDB.HasRows = True Then
While rdDB.Read()
col.Add(rdDB.Item(Field).ToString.Trim)
End While
End If
End Using
End With
txt.AutoCompleteSource = AutoCompleteSource.CustomSource
txt.AutoCompleteCustomSource = col
txt.AutoCompleteMode = AutoCompleteMode.Append
End Sub
End Module
وفي Form1 اضف
PHP كود :
Public Class Form1
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
If TextBox2.Focused = False Then Exit Sub
With comDB()
.CommandText = "SELECT * FROM TheResourceDetails WHERE DIRECTORNAME = '" & TextBox2.Text & "'"
Using RD = .ExecuteReader()
If RD.HasRows = True Then
RD.Read()
TextBox1.Text = RD!CompanyName
Else
TextBox1.Text = ""
End If
End Using
End With
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
If TextBox1.Focused = False Then Exit Sub
With comDB()
.CommandText = "SELECT * FROM TheResourceDetails WHERE CompanyName= '" & TextBox1.Text & "'"
Using RD = .ExecuteReader()
If RD.HasRows = True Then
RD.Read()
TextBox2.Text = RD!DIRECTORNAME
Else
TextBox2.Text = ""
End If
End Using
End With
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
FillList("TheResourceDetails", "CompanyName", TextBox1)
FillList("TheResourceDetails", "DIRECTORNAME", TextBox2)
End Sub
End Class
