Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 436
  • Last Modified:

Handle the result of a sqlcommand select statement

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

0
Un-Obtainium
Asked:
Un-Obtainium
  • 2
2 Solutions
 
sunithnairCommented:
Is there any specific reason for using 2 dimensional array? You could fill a dataset or you could move into into a generic list.
0
 
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
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
0
 
Un-ObtainiumAuthor Commented:
Thanks xDJR1875.

sunithnair
How would I put it into a dataset?
0
 
sunithnairCommented:
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

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now