ง่าย ๆ ก็ทำ Shared DataTable เอาไว้เป็น Datasource ครับ
ComboBox1 กำหนด Value = ฟิลด์รหัส, Text = ฟิลด์รหัส
ComboBox2 กำหนด Value = ฟิลด์รหัส, Text = ฟิลด์ชื่อ
Shared DataTable As DataTable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataTable = New DataTable
Dim CommandText As String = "SELECT [ID], [NAME] FROM TABLE1 ORDER BY [ID]"
Dim SQLConn As New SqlClient.SqlConnection("Data Source=(Local);Initial Catalog=ชื่อ Database;User Id=ชื่อ Login User;Password=รหัสผ่าน;")
Dim SQLDataAdapter As New SqlClient.SqlDataAdapter(CommandText, SQLConn)
SQLDataAdapter.Fill(DataTable)
ComboBox1.DataSource = DataTable
ComboBox2.DataSource = DataTable
ComboBox1.ValueMember = "ID"
ComboBox1.DisplayMember = "ID"
ComboBox2.ValueMember = "ID"
ComboBox2.DisplayMember = "NAME"
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataTable = New DataTable
Dim CommandText As String = "SELECT [ID], [NAME] FROM TABLE1 ORDER BY [ID]"
Dim SQLConn As New SqlClient.SqlConnection("Data Source=(Local);Initial Catalog=ชื่อ Database;User Id=ชื่อ Login User;Password=รหัสผ่าน;")
Dim SQLDataAdapter As New SqlClient.SqlDataAdapter(CommandText, SQLConn)
SQLDataAdapter.Fill(DataTable)
ComboBox1.DataSource = DataTable ComboBox2.DataSource = DataTable
ComboBox1.ValueMember = "ID"
ComboBox1.DisplayMember = "ID" ComboBox2.ValueMember = "ID" ComboBox2.DisplayMember = "NAME"
End Sub