accessing different columns

mcfly

Well-known member
Joined
Jun 15, 2009
Messages
54
Programming Experience
Beginner
i'm very much new to this, i have the following code:

VB.NET:
Dim connetionString As String
        Dim oledbCnn As OleDbConnection
        Dim oledbCmd As OleDbCommand
        Dim sql As String

        connetionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=H:\My Pictures\hotel_db.mdb;User Id=admin;Password=;"
        sql = "Select * from tbl_calendar"

        oledbCnn = New OleDbConnection(connetionString)

        Try
            oledbCnn.Open()
            oledbCmd = New OleDbCommand(sql, oledbCnn)
            Dim oledbReader As OleDbDataReader = oledbCmd.ExecuteReader()
            Do While oledbReader.Read

                ListBox1.Items.Add(oledbReader(0))
                ListBox1.Items.Add(oledbReader(1))
                ListBox1.Items.Add(oledbReader(2))

            Loop

            oledbReader.Close()
            oledbCmd.Dispose()
            oledbCnn.Close()
        Catch ex As Exception
            MsgBox("Can not open connection ! ")
        End Try

This works but all I need to know is what to change, probably on this line

VB.NET:
ListBox1.Items.Add(oledbReader(0))

So I can get a list of the data in just a particular column and not all the data...?

it's probably something very simple..any ideas???...
 
excellent that worked :D - sorry to be a simpleton but what if I wanted to just access say a particular column (as below), then the 5th record down - could I pass a variable to this line of code and it record the 5th record of that row?

Thats for the help also, you're a star
 
I am not sure i understand the question. Please rephrase it or provide some illustration.

Meanwhile i will guess that you want to refer some columns by their name while other by their index. So yes you can mix these. e.g.
VB.NET:
ListBox1.Items.Add(oledbReader("columnname").ToString())
ListBox1.Items.Add(oledbReader(index).ToString())
ListBox1.Items.Add(oledbReader(index).ToString())
ListBox1.Items.Add(oledbReader("columnname").ToString())
etc.
 
Back
Top