A newbie question... just getting my feet wet....
I know there is an elegant way to do this, but I'm not seeing it right now.
I have a form with several labels (N1...N27) and I would like to programatically fill the text of each label with names out of a database.
I can do one or several, but I'd like to put the code in a loop and have it all done....
Here's my existing code:
I would greatly appreciate any suggestions anyone would be able to offer...
Is the connection to the database being done the way it should be?? Don't I need to have something to sever the connection at the end of the sub??
Thanks!!
I know there is an elegant way to do this, but I'm not seeing it right now.
I have a form with several labels (N1...N27) and I would like to programatically fill the text of each label with names out of a database.
I can do one or several, but I'd like to put the code in a loop and have it all done....
Here's my existing code:
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Dim intCount As Integer
Dim Currentlbl As Integer
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = \\4fl-w2k01\public\OutOfOffice\OutOfOffice.mdb"
sql = "SELECT Employees.[First Name], Employees.[Last Name] FROM Employees ORDER BY Employees.[Last Name]"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "Names")
intCount = 0
N1.Text = ds.Tables("Names").Rows(0).Item(0) & " " & ds.Tables("Names").Rows(0).Item(1)
N2.Text = ds.Tables("Names").Rows(1).Item(0) & " " & ds.Tables("Names").Rows(1).Item(1)
N3.Text = ds.Tables("Names").Rows(2).Item(0) & " " & ds.Tables("Names").Rows(2).Item(1)
N4.Text = ds.Tables("Names").Rows(3).Item(0) & " " & ds.Tables("Names").Rows(3).Item(1)
N5.Text = ds.Tables("Names").Rows(4).Item(0) & " " & ds.Tables("Names").Rows(4).Item(1)
N6.Text = ds.Tables("Names").Rows(5).Item(0) & " " & ds.Tables("Names").Rows(5).Item(1)
I would greatly appreciate any suggestions anyone would be able to offer...
Is the connection to the database being done the way it should be?? Don't I need to have something to sever the connection at the end of the sub??
Thanks!!