superwei

导航

<2024年11月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

统计

常用链接

留言簿(4)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜

VB.NET2003 用OO4O方式连接Oracle(原创)

#Region "   ' OO4O Connect"
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim strSQL1 As String
        Dim strSQL2 As String
        Dim n As Integer
        Dim j As Integer
        Dim countC As Integer
        Dim countR As Integer
        Dim obj As Object
        Dim iora As OracleInProcServer.OraField
        Dim aoDataSet As DataSet
        aoDataSet = New DataSet
        Dim aoTable As DataTable
        aoDataSet.Tables.Add("aoTable")
        Dim ODyn As OraDynaset

        strSQL1 = "UPDATE T_MSG SET DELFLG = 0 WHERE MSGDISP = 1"
        strSQL2 = "SELECT * FROM superwei "
        Try
            Dim blnConnect As Boolean = OO4O_Connection()
            If blnConnect = False Then
                Exit Sub
            End If
            aoDataBase.BeginTrans()                 ' Begin Transaction
            'n = aoDataBase.ExecuteSQL(strSQL1)      ' normal SQL run
            ODyn = aoDataBase.CreateDynaset(strSQL2, ORADYN_READONLY)   ' return OraDynaset
            If ODyn.BOF Or ODyn.EOF Then
                MsgBox("Empty")
                Exit Sub
            Else
                ODyn.MoveFirst()
            End If

            aoDataSet = collectionChange(ODyn)
            'DataGrid1.DataSource = aoDataSet.Tables(0)
            Call disData(DataGrid1, aoDataSet)
            aoDataBase.Rollback()
        Catch ex As Exception
            MsgBox(Me.Text & ":" & ex.Message)
            TextBox1.Text = Me.Text & ":" & ex.Message
            aoDataBase.Rollback()
        End Try
    End Sub

    Function disData(ByVal Dgd As DataGrid, ByVal aoDataSet As DataSet)
        Dgd = Me.DataGrid1
        Dgd.DataSource = aoDataSet.Tables(0)
    End Function
#End Region

Module OO4O_Connect
    Public aoDataBase As OracleInProcServer.OraDatabase
    Public Overloads Function OO4O_Connection() As Boolean
        Dim oOraSession As OracleInProcServer.OraSession
        Try
            Dim oOraDataBase As Object
            Dim sConnectString As String
            Dim asHostName As String = "ips"

            sConnectString = "ips/ips"

            oOraSession = CreateObject("OracleInProcServer.XOraSession")

            aoDataBase = oOraSession.OpenDatabase(asHostName, sConnectString, 0)

            OO4O_Connection = True

        Catch ex As Exception
            MsgBox(ex.Message & " " & ex.ToString)
            OO4O_Connection = False
        End Try
    End Function

    Public Overloads Function OO4O_Connection(ByVal _aoDataBase As OracleInProcServer.OraDatabase) As OracleInProcServer.OraDatabase
        Dim oOraSession As OracleInProcServer.OraSession
        Try
            Dim oOraDataBase As Object
            Dim sConnectString As String
            Dim asHostName As String = "ips"

            sConnectString = "cho_objown/cho_objown"

            oOraSession = CreateObject("OracleInProcServer.XOraSession")

            _aoDataBase = oOraSession.OpenDatabase(asHostName, sConnectString, 0)

            Return _aoDataBase

        Catch ex As Exception
            MsgBox(ex.Message & " " & ex.ToString)
            'OO4O_Connection = False
        End Try
    End Function

End Module




posted on 2007-09-27 16:15 小辞猬 阅读(1126) 评论(0)  编辑  收藏 所属分类: DoNet


只有注册用户登录后才能发表评论。


网站导航: