Results 1 to 3 of 3

Thread: Storing Database Results into a Array

  1. #1

    Thread Starter
    Member Comn8u's Avatar
    Join Date
    Jul 2004
    Posts
    35

    Storing Database Results into a Array

    How would I go about storing one column in a database in a Array?

    And then how would I extract those results from the array?

  2. #2

    Thread Starter
    Member Comn8u's Avatar
    Join Date
    Jul 2004
    Posts
    35

    Smile RE:

    Or I should say, How would I go about taking one column from a database result and store it into an array.


  3. #3
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    this?
    VB Code:
    1. Dim cn As New SqlConnection()
    2.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    3.       cn.ConnectionString = "user id=sa;password=password;initial catalog=northwind"
    4.       cn.Open()
    5.  
    6.       Dim cm As New SqlCommand("select * from territories", cn)
    7.       Dim dr As SqlDataReader = cm.ExecuteReader
    8.       Dim a As New ArrayList()
    9.       While dr.Read
    10.          a.Add(dr(1)) ' second column
    11.       End While
    12.  
    13.       Dim s As String
    14.       Dim s2 As String
    15.       For Each s In a
    16.          s2 &= s & Constants.vbCrLf
    17.       Next
    18.       MessageBox.Show(s2)
    19.  
    20.    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width