Find size of GetString in DataReader (vb.net)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All

I'm doing a 'select * from table' in my DataReader below and populating an
array with the results. Obvisouly I'm only getting the first field from the
results by the use of the GetString(0).

My Question is how do I find out how many elements there are to GetString
without having to know how many fields are in the table?

Thanks
-- Code

Dim List As New ArrayList()
Dim ListCount As Integer = 0
Dim ListReader As SqlDataReader = ListCmd.ExecuteReader()
While ListReader.Read()
List.Insert(ListCount, ListReader.GetString(0))
ListCount = ListCount + 1
End While

--
 
Use the property SqlDataReader.FieldCount

Hi All

I'm doing a 'select * from table' in my DataReader below and populating an
array with the results. Obvisouly I'm only getting the first field from the
results by the use of the GetString(0).

My Question is how do I find out how many elements there are to GetString
without having to know how many fields are in the table?

Thanks
-- Code

Dim List As New ArrayList()
Dim ListCount As Integer = 0
Dim ListReader As SqlDataReader = ListCmd.ExecuteReader()
While ListReader.Read()
List.Insert(ListCount, ListReader.GetString(0))
ListCount = ListCount + 1
End While

--
 
Thanks Shiva - Jus got back into work and seen your reply. Kind of worked it
out while I was away. Nice and easy one.

Anyway - thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top