Connecting Tech Pros Worldwide Help | Site Map

Store database values in array

Newbie
 
Join Date: Mar 2009
Posts: 10
#1: Apr 4 '09
Dear Techies,

I have a code which retrieves values from database
Expand|Select|Wrap|Line Numbers
  1. cmdSelect = New OleDbCommand("select fields,finesFields from trafficReport where checked LIKE 1", conn)
  2.         cmdSelectDr = cmdSelect.ExecuteReader
  3.  
  4.         While cmdSelectDr.Read
  5.             MsgBox("Select " + cmdSelectDr(0) + cmdSelectDr(1) + " from fines")
  6.             'strtest = cmdSelectDr(0)
  7.  
  8.             'Store all values in array here
  9.         End While

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

Any help would be highly appreciated

thanks
Nadir
iam_clint's Avatar
Forum Leader
 
Join Date: Jul 2006
Location: Oklahoma
Posts: 1,076
#2: Apr 14 '09

re: Store database values in array


You could do something like this ->
Expand|Select|Wrap|Line Numbers
  1. dim ds as new dataset
  2. dim dbadap as new sqldataadapter
  3. cmdSelect = New OleDbCommand("select fields,finesFields from trafficReport where checked LIKE 1", conn)
  4. dbadap.fill(ds, "trafficReport")
  5.  
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?
Newbie
 
Join Date: Mar 2009
Posts: 10
#3: Apr 15 '09

re: Store database values in array


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


Many thanks
Nadir Firfire
iam_clint's Avatar
Forum Leader
 
Join Date: Jul 2006
Location: Oklahoma
Posts: 1,076
#4: Apr 15 '09

re: Store database values in array


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

Expand|Select|Wrap|Line Numbers
  1. for each rs as datarow in ds.tables(0).rows
  2.    msgbox(rs("traffic_id"))
  3. next
  4.  
or something similiar along those lines. you can also update the dataset simply by

Expand|Select|Wrap|Line Numbers
  1. for each rs as datarow in ds.tables(0).rows
  2.  if conditions then
  3.    rs("traffic_id")=1
  4. end if
  5. next
  6.  
Reply