getting oracle table results into array using odp.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • erbrose
    New Member
    • Oct 2006
    • 58

    #1

    getting oracle table results into array using odp.net

    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 OracleDataReade r 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 OracleConnectio n(oradb) ' Visual Basic
    Inconn.Connecti onString = oradb
    Inconn.Open()

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

    Dim cmd As New OracleCommand(s ql, Inconn)
    cmd.CommandType = CommandType.Tex t

    Dim inRS As OracleDataReade r = cmd.ExecuteRead er()

    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
  • erbrose
    New Member
    • Oct 2006
    • 58

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

    /CODE

    Dim arrTemp As String


    Dim inRS As OracleDataReade r = cmd.ExecuteRead er()

    While inRS.Read()
    'arrTemp.ToStri ng = inRS("USERNAME" )

    arrTemp = arrTemp & "," & inRS.Item("USER NAME")

    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

    getArrayOfTable s = arrTemp3

    inRS.Close()
    Inconn.Close()

    /CODE

    Comment

    Working...