VB连接oracle9I数据库

Option Explicit
Public appdisk As String
Public conn As New ADODB.Connection
Public Rs As New ADODB.Recordset
Public db As String
Private sSQL As String

Private Sub Command1_Click()
   
    If Trim(Text1.Text) = "" Then
        MsgBox "must input", vbCritical, "error"
        Text1.SetFocus
        Exit Sub
    End If
   
    If Trim(Text2.Text) = "" Then
        MsgBox "must input", vbCritical, "error"
        Text2.SetFocus
        Exit Sub
    End If

    sSQL = "select * from USERID where id='" & Trim(Text1.Text) & "'"
    Rs.Open sSQL, conn, adOpenKeyset, adLockPessimistic
    If Rs.EOF = True Then
        MsgBox "no this user", vbCritical, "error"
        Text1.SetFocus
        Rs.Close: Set Rs = Nothing
        Exit Sub
    End If

    Rs.Close: Set Rs = Nothing
   
    sSQL = "select * from USERID where id='" & Trim(Text1.Text) & "' and password='" & Trim(Text2.Text) & "'"
    Rs.Open sSQL, conn, adOpenKeyset, adLockPessimistic
    If Rs.EOF = True Then
        MsgBox "password is wrong", vbCritical, "error"
        Text2.SetFocus
        Rs.Close: Set Rs = Nothing
        Exit Sub
    Else
        If Val(Rs!Levels) = 0 Then
            Form2.Show 1
        Else
            Form3.Show 1
        End If
    End If

    Rs.Close: Set Rs = Nothing
End Sub

Private Sub Command2_Click()
    End
End Sub

Private Sub Form_Load()
    Dim i As Integer
   
    On Error GoTo Err
   
    appdisk = Trim(App.Path)
    If Right(appdisk, 1) <> "/" Then appdisk = appdisk & "/"
    db = appdisk
    db = "Provider=MSDAORA.1;Password=chun;User ID=chun;Data Source=chun;Persist Security Info=True"
    conn.CursorLocation = adUseClient
    conn.Open db
    Exit Sub
   
Err:
    MsgBox Err.Number
    Unload Me

End Sub

'自己建立from吧  from1的代码就是这些  我得库名是CHUN 你给改成自己的就可以了  就下面这句话

你可能感兴趣的:(VB连接oracle9I数据库)