Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

List Box

$
0
0
Hi

Was amazed at how fast people helped on my last problem and it really did dig me out of a whole

i was wondering if anybody could help wtih some list box code

I have a userform with a list box in

I want the list box to show all the rows of data in my connected sql database (eventually have a user select a row and open up a record)

the code i am using at the moment is below

could anyone advise?

thanks steve

Public dbconn As New MySqlConnection
Public sql As String
Public dbcomm As MySqlCommand
Public dbread As MySqlDataReader
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

dbconn = New MySqlConnection("Data Source=localhost;user id=root;password=xx;database=xx;")

Try
dbconn.Open()
Catch ex As Exception
MsgBox("Error in connection, please check Database and connection server.")
End Try

sql = "SELECT * FROM main"
Try
dbcomm = New MySqlCommand(sql, dbconn)
dbread = dbcomm.ExecuteReader()

While dbread.Read
ListBox1.Items.Add(dbread("Company_name"))
ListBox1.Items.Add(dbread("Contact"))
ListBox1.Items.Add(dbread("Consultant"))
ListBox1.Items.Add(dbread("Postcode"))
ListBox1.Items.Add(dbread("Sector"))
ListBox1.Items.Add(dbread("HotList"))
End While

dbread.Close()
Catch ex As Exception
MsgBox("Error in collecting data from Database. Error is :" & ex.Message)
dbread.Close()
Exit Sub
End Try
End Sub
End Class

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>