I'm studying Visual Basic (using Visual Studio 2008) as part of an all-round IT foundation degree...I must confess that programming is becoming my weak spot! Unlike the C++ I was taught last year, I'm not finding VB too easy...probably becasue I've never programmed this way before and I've missed a couple of lessons.
I'm writing a program that accesses an Access Database. The bit of it I'm having problems with at the moment concerns populating a list box with the contents of a table from the database.
What I want to know is how do I have the data in columns in the list box? The table that the data is coming from is 4 columns wide, and has 14 records in in total. At the moment, it fills the list box in one column....fields one underneath the other...
Here's my code:
Private Sub citydata_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dataCity As New DataTable() Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=E:\globexdata\globex.mdb" Dim sqlString As String = "SELECT * FROM cities" Dim dataAdapt As New OleDb.OleDbDataAdapter(sqlString, connectionString) dataAdapt.Fill(dataCity) dataAdapt.Dispose() For r = 1 To dataCity.Rows.Count For c = 1 To dataCity.Columns.Count lstPopulation.Items.Add(dataCity(r - 1)(c - 1)) Next c Next r End Sub
I hope someone can help! I may have a lot more questions over the next week...beyond the basics I'm finding VB hell!!