|
-
Jan 24th, 2006, 05:22 AM
#1
Thread Starter
Addicted Member
Array value problem
Hi
I am trying to extract the values from a table and populate a virtual table, which is working fine, however I then want to take those values and populate an array, unfortunately I keep getting the values 1 and 3 for some reason, instead of the values in the actual table,
I would be grateful for any advice.
_product.versionid = _productversionid ' get the select record version id
_dsDataSet = _product.ProductSQL(Cls_Products.ProductDetails.ProductChildFormulas) 'select the child formula id's
Dim dt As New DataTable("formulatable") 'create a virtual table
dt.Columns.Add("versionchildid") 'create a virtual column to hold child formula id's
For Each dr As DataRow In _dsDataSet.Tables("product").Rows 'select all the child id's
dt.Rows.Add(New Object() {dr("childproductversionid")}) 'and add them to the table
Next 'move to the next record
If dt.Rows.Count > 0 Then 'if any rows are returned, we can create an array to query the formula version table
Dim dataList As New ArrayList
For Each dr As DataRow In dt.Rows 'for each row in table add the value to the array
dataList.Add(dr.Item(0))
MsgBox(dataList.Add(dr.Item(0)).ToString)
Next
-
Jan 24th, 2006, 06:30 AM
#2
PowerPoster
Re: Array value problem
Hi,
I,m wondering why
MsgBox(dataList.Add(dr.Item(0)).ToString)
works???
If you must use MsgBox then shouldn't it be
MsgBox(dr.Item(0).ToString) ??
Have you put a breakpoint on
dataList.Add(dr.Item(0))
to check the various values at that point?
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jan 24th, 2006, 06:52 AM
#3
Re: Array value problem
ArrayList.Add returns the index at which the new item was added. This code:
VB Code:
dataList.Add(dr.Item(0))
MsgBox(dataList.Add(dr.Item(0)).ToString)
is adding the same value to the ArrayList twice. You are calling MsgBox every second time so you will get the indexes 1, 3, 5, 7, etc. May I suggest reading the help topics for properties, methods, etc. rather than assuming they work a certain way, particularly if they appear to not be working as you expect. From the help:
Return Value
The ArrayList index at which the value has been added.
Could have saved yourself some time and heartache.
-
Jan 24th, 2006, 06:56 AM
#4
Thread Starter
Addicted Member
Re: Array value problem
yeah you are right.
I was only using the message box, so I could see what the return values were..
I have got the table and array working now, like so....
Dim dataList As New ArrayList 'create an array to hold values
For Each dr As DataRow In dt.Rows 'get the value from each row in the table
dataList.Add(dr.Item(0)) 'add the value to array
Next
But I still want to check I have the correct values in the array, before I go onto the next bit! is there a way of checking this?
And do I really need to create a table in the first place? could I not just pass the values from the dataset into an array?? (somehow)
Thanks
-
Jan 24th, 2006, 07:07 AM
#5
Thread Starter
Addicted Member
Re: Array value problem
Ok, found by inserting a break point.
Bit new to all this, used to ASP but now trying out VB.Net for past couple months.
I notice taxes that you like Virginia!
I was there last year, James Town, York Town, Richmond, Blue Ridge Mountains etc etc, had really good time.
Anyway
Thanks for help.
Last edited by soluga; Jan 24th, 2006 at 07:10 AM.
-
Jan 24th, 2006, 09:52 AM
#6
Thread Starter
Addicted Member
Re: Array value problem
Hi
New Problem now..
When I call my class, I want to loop through the array, calling a sql select for each value like so....
For Each childproductversionid As String In list
_sqlString = "Select * From productversion " & _
" Where productversionid = '" & childproductversionid & "'"
Next
But I am only getting the final record!
Would be grateful for any advice.
Thanks
-
Jan 24th, 2006, 12:16 PM
#7
PowerPoster
Re: Array value problem
 Originally Posted by soluga
Ok, found by inserting a break point.
Bit new to all this, used to ASP but now trying out VB.Net for past couple months.
I notice taxes that you like Virginia!
I was there last year, James Town, York Town, Richmond, Blue Ridge Mountains etc etc, had really good time.
Anyway
Thanks for help.
I've just come back after spending a month with family in North Western Virginia (Culpeper area). Well within sight of the Blue Ridge Mountains. Out in the wilds, no broadband
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jan 24th, 2006, 05:49 PM
#8
Re: Array value problem
 Originally Posted by soluga
Hi
New Problem now..
When I call my class, I want to loop through the array, calling a sql select for each value like so....
For Each childproductversionid As String In list
_sqlString = "Select * From productversion " & _
" Where productversionid = '" & childproductversionid & "'"
Next
But I am only getting the final record!
Would be grateful for any advice.
Thanks
This is a new question and should have been asked in a new thread.
What exactly do you expect to happen? Think about what you want to happen and what exactly that code inside the For loop does and I think you'll see that they are not the same thing.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|