VB.NET Connect Oracle

Prerequisites: Install oracle9/10g Client.  configure the TNSNAME.ora

Connect oracle database case by OracleConnection:

Private Sub BtnOracle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOracle.Click

        Dim OracleConn As New OracleConnection
        Dim OracleCom As New OracleCommand
        OracleConn.ConnectionString = "user id=RCOTRPR1;data source='a3cotr.ncs.com';password=RCOTRPR1"
        Dim branch As String
        branch = TxtBranch.Text

        Try
            OracleConn.Open()
            Dim sql As String = "select branchname from cots_tab_branch where branch =" & branch
            Dim cmd As New OracleCommand(sql, OracleConn)
            cmd.CommandType = CommandType.Text

            Dim dr As OracleDataReader = cmd.ExecuteReader()
            dr.Read()
            MessageBox.Show(dr.Item("branchname"), "oracle")
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString())

        Finally
            OracleConn.Dispose()

        End Try

 

    End Sub

 

你可能感兴趣的:(oracle,sql,.net,vb,VB.NET)