Connecting Tech Pros Worldwide Help | Site Map

getting oracle table results into array using odp.net

Member
 
Join Date: Oct 2006
Posts: 35
#1: Oct 5 '09
Hey all,
So hopefully this is a quick fix but for the life of me I can't figure out how to get my results from a OracleDataReader record set.
Just trying to get all the users for a specific TNS into an array. I was able to do this easily before with ADODB, but thought I would try using ODP.net.

Here is what I have so far and it definitely gets all the USERs for a given TNS. its when I get to the READ() part where the syntax is ???

'TNSname, User and password are all variables declared before this

/CODE

Dim oradb As String = "Data Source=" & TNSname & ";User Id=" & User & ";Password=" & password & ";" ' Visual Basic
Dim Inconn As New OracleConnection(oradb) ' Visual Basic
Inconn.ConnectionString = oradb
Inconn.Open()

Dim sql As String = "SELECT USERNAME FROM dba_users where default_tablespace != 'SYSAUX' and default_tablespace != 'SYSTEM' and default_tablespace != 'TOOLS' and default_tablespace != 'USERS' ORDER BY USERNAME" ' Visual Basic

Dim cmd As New OracleCommand(sql, Inconn)
cmd.CommandType = CommandType.Text

Dim inRS As OracleDataReader = cmd.ExecuteReader()

Dim arrTemp() As String = {}
Dim i As Integer = 0

While inRS.Read()

arrTemp(i) = inRS.GetString(0).ToString
i = i + 1

End While

inRS.Close()
Inconn.Close()

/CODE

Its strange as I can easily populate a text or combo box during the read by just saying

While inRS.Read()
cbo_test.items.add(inRS.Item("USERNAME"))
End While

I would appreciate anyones thoughts and or direction here as I would rather not go back to ADOBD...
Thanks ahead of time!
Cheers,
Eric
Member
 
Join Date: Oct 2006
Posts: 35
#2: Oct 6 '09

re: getting oracle table results into array using odp.net


well its long winded and slightly backwards but it works....

/CODE

Dim arrTemp As String


Dim inRS As OracleDataReader = cmd.ExecuteReader()

While inRS.Read()
'arrTemp.ToString = inRS("USERNAME")

arrTemp = arrTemp & "," & inRS.Item("USERNAME")

End While

Dim arrTemp2() As String = {}
arrTemp2 = Split(arrTemp, ",")

Dim arrTemp3() As String = {}
ReDim arrTemp3(UBound(arrTemp2) - 1)

Dim j As Integer = 0

For i As Integer = 1 To UBound(arrTemp2) - 1
arrTemp3(j) = arrTemp2(i)
j = j + 1
Next

getArrayOfTables = arrTemp3

inRS.Close()
Inconn.Close()

/CODE
Reply