1. On the Form and Combobox control and name it anything you like
2. On Form_Load event and the code below:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 'Specify the datasource Dim CONNECTION_STRING As String = "Data Source=LOCALHOST;Initial Catalog=DB_NAME; Integrated Security=True" Dim conn As SqlConnection = New SqlConnection(CONNECTION_STRING) 'Specify the SELECT query Dim cmd As SqlCommand = New SqlCommand("SELECT ProductName FROM ProductTable", conn) 'Open the Database conn.Open() Dim sdr As SqlDataReader = cmd.ExecuteReader 'Do the adding through looping While sdr.Read() If Not sdr("ProductName").ToString = String.Empty Then product.Items.Add(sdr.Item("ProductName").ToString) End While 'Close the Database conn.Close() End Sub
No comments:
Post a Comment