VB.NET 2005 with Oracle 9i

OK..this has been troubling me since quite few days..
Im not able to connect from VB.NET 2005 to oracle content...:S

In VB 6.0 i used adodb to connect oracle 9i as backend .. no issues then..
consider the following code..( in vb 6.0 )

--------------------------------------------------------------------------\
Dim
(general declarations)
Dim d As New ADODB.Connection
Dim r As New ADODB.Recordset

Private Sub as_Change()
End Sub

Private Sub Command1_Click()
If text1.Text = r(0) And Text2.Text = r(1) Then
MsgBox("Data connected successfully...")
Else
MsgBox("Information entered is wrong,Please enter correctly", vbCritical, "Error")
End If
End Sub

(form load)
Private Sub Form_Load()
Set d = New ADODB.Connection
Set r = New ADODB.Recordset
d.Open "girish", "scott", "tiger"
r.Open "select * from vidlogin", d, adOpenKeyset, adLockPessimistic
End Sub
-----------------------------------------------------------------
& i tried similar coding in vb.net 2005...& damn it...even this simple POS thing wont work..

following is my code in .net 2005..please spot the error & help me please please :cry:
(added reference of adodb to the project)

-----------------------------------------------------------------

(form1 declarations) .. ( i coudnt find general declarations...:S)

Public Class Form1
Dim d As New ADODB.Connection
Dim r As New ADODB.Recordset

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If (Text1.Text = r(0) And Text2.Text = r(1)) Then
MsgBox("success....connected..:)")
End If
End Sub

Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub

(form1 --- > new) .. (coudnt find form --> load :( )
Public Sub New()
d = New ADODB.Connection
r = New ADODB.Recordset
d.Open("girish", "scott", "tiger")
r.Open("select * from vidlogin", d, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockPessimistic)
MsgBox("connection success")
' This call is required by the Windows Form Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.

End Sub
End Class

-----------------------------------------------------------------
Please tell me where i have to change what..or please write me the equivalent script that will work in vb.net 2005..:)

girish -- > odbc connection for oracle
vidlogin --> table name in oracle with useid scott & pass tiger.
only 2 fields in the table ..:)

Regards,
SS
 
I dont have oracle, i m posting sample with SQL

Code:
Imports ADODB
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(472, 254)
        Me.Name = "Form1"
        Me.Text = "Form1"

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim conn As New ADODB.Connection
        Dim rs As New ADODB.Recordset
        conn.Open("Provider = SQLOLEDB;user id = sa;password = ;Initial Catalog = Pubs;Data Source = SOFTWARE-143")
        Dim SQL As String = "select * from Titles"
        rs.Open(SQL, conn, 3, 3)
        MsgBox(rs.RecordCount)
        rs.Close()
        conn.Close()
    End Sub
----------------------------
Hope its simple to understand... if not let me know...
 
mainly the error is coming up at

" Text1.Text = r(0) " point,,,it gives the error message that

"invalid cast exception was unhandled"

--> "unable to cast object of type 'Adodb.internalfield' to 'System.String' "

:S :S

what i mean to say is

1) the connection is established..

2) record count is visible..

but the syntax to access the fields in the table (oracle ) is different i think..

in vb 6.0 .. if the recordset was rs

( dim rs as adodb.recordset

rs.Open("select * from vidlogin", d, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockPessimistic)

i could access the records in this format rs(0), & rs(1)

the accessing syntax in vb.net 2.0 must be different cause im getting error only in this part...:S//
 
Back
Top