We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Handle the result of a sqlcommand select statement

Medium Priority
452 Views
Last Modified: 2012-05-06
I am sending a select statement to my database which is returning 2 columns and x rows. How do I put this result into a 2 dimensional array so I can use it later.
Dim myCommand As SqlCommand
Dim dr As SqlDataReader
**Connection opened here
myCommand = New SqlCommand("Select Person, Email From Emails", myConnection)
dr = myCommand.ExecuteReader
 
'TODO Fill 2 dimensional array here.

Open in new window

Comment
Watch Question

Is there any specific reason for using 2 dimensional array? You could fill a dataset or you could move into into a generic list.
Software Applications Developer / Integrator
CERTIFIED EXPERT
Commented:
something like the following should get you started.

dim irow as integer
dim icell as integer
irow = 0
icell = 0
while dr.read()
   myarray(irow,icell) = dr(0).ToString()
   myarray(irow,icell+1) = dr(1).ToString()
   irow = irow + 1
wend

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thanks xDJR1875.

sunithnair
How would I put it into a dataset?
Like this better use DataTable
Dim myCommand As SqlCommand
**Connection opened here
myCommand = New SqlCommand("Select Person, Email From Emails", myConnection)
Dim sqlDataAdapter As SqlDataAdapter = New SqlDataAdapter(myCommand)
Dim dataTable As DataTable = New DataTable("Emails")
sqlDataAdapter.Fill(dataTable)

Open in new window

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.