If i have a table with say x columns and y rows
how do i get the contents of the 'i'th column into a arraylist

8 Years
Discussion Span
Last Post by tuse

Well the number of rows really do not matter.

In the code that I have posted below, I hold the number of rows in a variable named total.

I have chosen to extract the contents of the first column, if you want to do so for the column number x, substitute 0 by x-1 in the statement below in the code-

a(i) = ds.Tables("trial1").Rows(i).Item(0)

I am adding the contents retrieved to a ListBox, just as a check.

Public Class Form1

    Dim a() As String
    Dim total As Integer

    Dim cn As New Odbc.OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=shreyas; User=root;Password=;")
    Dim cmd As Odbc.OdbcCommand
    Dim adp As Odbc.OdbcDataAdapter
    Dim ds As New DataSet

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cmd = New Odbc.OdbcCommand("Select * from trial1", cn)
        adp = New Odbc.OdbcDataAdapter(cmd)
        adp.Fill(ds, "trial1")
        'Count the number of rows
       total = ds.Tables("trial1").Rows.Count - 1

        Dim i As Integer

        ReDim a(0 To total)
        For i = 0 To total
            a(i) = ds.Tables("trial1").Rows(i).Item(0)

        Dim j As Integer

        For j = 0 To total

    End Sub
End Class
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.