Retriving array values



 While m_reader.Read
            If Not m_reader("cname") = "" Then
                arryname.Add(m_reader("cname"))
 arrymail.Add(m_reader("mail"))
            End If
        End While


 For Each item As String In arryname

        Next



i hve the above code in which i am adding the fields 2 array
for retriving the values of each field i will need to execute the for loop twice
how can i retive values of both array items using a single loop

Since you seem to be using a very basic array for both items, you could do this.

Dim item As Integer
For item As Integer = 0 To arryname.Length - 1
  'arryname(item)
  'arrymail(item)
Next

And to cover any rare situations where the array lengths may end up different

Dim item As Integer
For item As Integer = 0 To arryname.Length - 1
  If item < arryname.Length Then
    'arryname(item)
  End If

  If item < arrymail.Length Then
    'arrymail(item)
  End If
Next

refercing elow but i get error in .add , error at from

http://stackoverflow.com/questions/4255308/building-a-multidimensional-array-in-vb-net/4255327#4255327

tried using
Dim dictionary As New Dictionary(Of String, String)

Dim m_readersc As SqlDataReader = cmdsc1.ExecuteReader()
While m_readersc.Read
If Not m_readersc(“cname”) = “” Then
dictionary.Add(m_readersc(“cid”), m_readersc(“cname”))
End If
End While

errror index out of range

On which line… I assume it is referring to your m_readsc(“cid”) or m_readsc(“cname”) as your current code isn’t trying to read from the Dictionary at this point.

the abovr errr was due to a blank field. now i get thee belowerror

Value of type ‘String’ cannot be converted to ‘System.Collections.Generic.Dictionary(Of String, String)’.

For Each value As Dictionary(Of String, String) In dictionary
Dim id As String = value(“cid”)
Dim description As String = value(“cname”)
Next

Use your debugger, it should make it obvious which of those arrays have an index out of range and it won’t be the dictionary.