'cn is a connection.
'in your form load event
'declare a datatable
Dim dt As New DataTable()
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dt.Columns.Add(New DataColumn("id"))
End Sub
'it loads the first column of the table authors to the combobox
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
cn.Open()
Dim cm As New SqlCommand("select * from authors", cn)
Dim dr As SqlDataReader = cm.ExecuteReader
While dr.Read
Me.ComboBox1.Items.Add(dr(0).ToString)
End While
dr.Close()
cn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
'in your combobox selectedindex change event
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim dr As DataRow = dt.NewRow
dr(0) = ComboBox1.SelectedItem.ToString
dt.Rows.Add(dr)
End Sub