Store database values in array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nady
    New Member
    • Mar 2009
    • 10

    Store database values in array

    Dear Techies,

    I have a code which retrieves values from database
    Code:
    cmdSelect = New OleDbCommand("select fields,finesFields from trafficReport where checked LIKE 1", conn)
            cmdSelectDr = cmdSelect.ExecuteReader
    
            While cmdSelectDr.Read
                MsgBox("Select " + cmdSelectDr(0) + cmdSelectDr(1) + " from fines")
                'strtest = cmdSelectDr(0)
    
                'Store all values in array here
            End While

    i want to store all the values in a array for further processing.

    Any help would be highly appreciated

    thanks
    Nadir
    Last edited by Frinavale; Apr 17 '09, 06:45 PM. Reason: Added code tags. Please post code in [code] [/code] tags
  • iam_clint
    Recognized Expert Top Contributor
    • Jul 2006
    • 1207

    #2
    You could do something like this ->
    Code:
    dim ds as new dataset
    dim dbadap as new sqldataadapter
    cmdSelect = New OleDbCommand("select fields,finesFields from trafficReport where checked LIKE 1", conn)
    dbadap.fill(ds, "trafficReport")
    So your table is stored locally in a dataset and be used again else where... I don't see any reason to really store this data into an array?

    Comment

    • nady
      New Member
      • Mar 2009
      • 10

      #3
      Hi,
      thanks for the reply.
      the reason why i need to store in array is i need for further processing.


      Many thanks
      Nadir Firfire

      Comment

      • iam_clint
        Recognized Expert Top Contributor
        • Jul 2006
        • 1207

        #4
        Well when you set it in a dataset all the values are still there just stored on the server rather than the sql db..

        so after you fill the ds like i showed above later on you can do

        Code:
        for each rs as datarow in ds.tables(0).rows
           msgbox(rs("traffic_id"))
        next
        or something similiar along those lines. you can also update the dataset simply by

        Code:
        for each rs as datarow in ds.tables(0).rows
         if conditions then
           rs("traffic_id")=1
        end if
        next

        Comment

        Working...