New programmer here and asking your forgiveness on such a novice issue...hahaha
Have a windows form app that when i click a button, it connects to a SQL database and retrieves data from a table. I then want this data to display in a checkedlistbox.
It runs and returns no errors, but also does not display the data in my checkedlistbox
Here is the code from the button:
Have a windows form app that when i click a button, it connects to a SQL database and retrieves data from a table. I then want this data to display in a checkedlistbox.
It runs and returns no errors, but also does not display the data in my checkedlistbox
Here is the code from the button:
Private Sub btn_LoadImages_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_LoadImages.Click
Dim conn As New SqlClient.SqlConnection
' TODO: Modify the connection string and include any
' additional required properties for your database.
conn.ConnectionString = "integrated security=SSPI;data source=ABC;" & _
"persist security info=False;initial catalog= website"
Try
conn.Open()
MessageBox.Show("Connected to SQL Database")
Catch ex As Exception
MessageBox.Show("Failed to connect to data source")
End Try
' Insert code to process data.'
Dim myCMD As SqlClient.SqlCommand = New SqlClient.SqlCommand("SELECT strProducerID from dbo.tblProducer", conn)
Dim myDataReader As SqlClient.SqlDataReader = myCMD.ExecuteReader
If myDataReader.HasRows > 0 Then
CheckedListBox1.DataSource = myDataReader
CheckedListBox1.DisplayMember = "strCompanyName"
CheckedListBox1.ValueMember = "intProducerID"
End If
conn.Close()
End Sub