Results 1 to 7 of 7

Thread: vb-oracle query

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2002
    Posts
    22

    Question vb-oracle query

    hi,

    i was using this code to access data from a table in oracle -

    dim cn as new adodb.connection
    dim rs as new adodb.recordset
    dim str as string

    str="select * from products"
    cn.connectionstring ="dsn=aaa;uid=aaa;pwd=aaa"
    cn.open
    rs.open str,cn

    now the problem is if that if the table doesnt exist, i get an error which is pretty much obvious. my question is how do i trap this error in VB. or may be how do i code to check whether a table exists in oracle or not. thanks

  2. #2
    Hyperactive Member GlenW's Avatar
    Join Date
    Nov 2001
    Location
    Gateshead, England
    Posts
    479
    Use ADOX Catalog

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2002
    Posts
    22

    Question re: vb-oracle query

    hi glenn,

    could you please elaborate a bit on this. thanks.

  4. #4
    Hyperactive Member GlenW's Avatar
    Join Date
    Nov 2001
    Location
    Gateshead, England
    Posts
    479
    Reference;
    'Microsoft ADO Ext. 2.5 for DDl and Security'

    VB Code:
    1. Dim cnnCon As ADODB.Connection
    2. Set cnnCon = New ADODB.Connection
    3. cnnCon.Mode = adModeRead
    4. Dim myCat As New ADOX.Catalog
    5.    
    6. cnnCon.Open dataText  
    7.  
    8. Set myCat.ActiveConnection = cnnCon
    9.  
    10. While (i < myCat.Tables.Count)
    11.         If ((myCat.Tables(i).Name = "tblMyTable") _
    12.         'Do whatever
    13.         End If
    14.         i = i + 1
    15. Wend

    Something like this will enable you to fing if a table exists

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    To error trap GlenW's code
    VB Code:
    1. Private Sub OpenCat()
    2. On Error Goto ErrRtn
    3. Dim cnnCon As ADODB.Connection
    4. Set cnnCon = New ADODB.Connection
    5. cnnCon.Mode = adModeRead
    6. Dim myCat As New ADOX.Catalog
    7.    
    8. cnnCon.Open dataText  
    9.  
    10. Set myCat.ActiveConnection = cnnCon
    11.  
    12. While (i < myCat.Tables.Count)
    13.         If ((myCat.Tables(i).Name = "tblMyTable") _
    14.         'Do whatever
    15.         End If
    16.         i = i + 1
    17. Wend
    18. Exit Sub
    19. ErrRtn:
    20. Msgbox Err & " " & Error
    21. End Sub

  6. #6
    Hyperactive Member GlenW's Avatar
    Join Date
    Nov 2001
    Location
    Gateshead, England
    Posts
    479
    Hack, you're just a bloody perfectionist!!

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    I wouldn't have touched your code had it not been for the fact that kaustav asked, in his original question, how do I error trap (well, maybe I would have anyway...I've just had too many dealings with runtime error that blow my users back to the desktop resulting in angry phone calls say "Hack, your stinkin' program don't work, FIX IT!!")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width