各位好:
    我現在正學習一個寫一個小程序 ,一個系統進入窗體,用來輸入用戶名和密碼的,用ADODC控件來邊接SQL數據庫,從而判斷用戶是否存在,請教各位詳細的介紹好嗎!!
謝謝!!!!

解决方案 »

  1.   

    Set cnSQL = New ADODB.Connection
       
       strCon = "Driver={sql server};server=" & Trim(txtServer.Text) & ";uid=" & Trim(txtUser.Text) & ";pwd=" & Trim(txtPws.Text) & ";database=" & Trim(txtDatabase.Text)
       cnSQL.CommandTimeout = 1000
       cnSQL.CursorLocation = adUseServer
       cnSQL.Open strCon
       
        If cnSQL.State = 1 And Err.Number = 0 Then        bConnect = True
            MsgBox "Connection success!", vbOKOnly + vbInformation
        Else
            
    '    Else
            Set cnSQL = Nothing
            bConnect = False
            MsgBox "Connection failed!", vbOKOnly + vbInformation
        End If
      

  2.   

    不要用ADODC了,太垃圾了.用ADODB吧.
      

  3.   

    Dim mrc As ADODB.Recordset
        txtsql = "select username,password from use where username='" & _
            Trim(Text1.Text) & "'"
        Set mrc = ExecuteSQL(txtsql)  '查询用户
        If mrc.EOF = True Then
            MsgBox " 用户名错误!", vbExclamation + vbOKOnly, "警告"
            Text1.SetFocus
            Text1.SelStart = 0
            Text1.SelLength = Len(Text1.Text)
            Exit Sub
        End If
        username = mrc.Fields(0)
        If Trim(Text2.Text) <> mrc.Fields(1) Then
            MsgBox " 密码错误!", vbExclamation + vbOKOnly, "警告"
            Text2.SetFocus
            Text2.SelStart = 0
            Text2.SelLength = Len(Text2.Text)
            Exit Sub
        End If
        '显示主窗体
        MDIForm1.Show
        '卸载登录窗体
        Unload Me不要管人家用什么!回答了,给分就行!
      

  4.   

    Private Sub Command1_Click()
        Adodc1.RecordSource = "Select * From mLogin Where UserName = '" & Text1.Text & "' And PassWord = '" & Text2.Text & "'"
        Adodc1.Refresh
        If Adodc1.Recordset.BOF And Adodc1.Recordset.EOF Then
            MsgBox "用户名或密码错,请重输!"
            Text1.SetFocus
        Else
            MDIForm1.Show
            Unload Me
        End If
    End SubPrivate Sub Form_Load()
        Adodc1.Visible = False
        Adodc1.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=;Initial Catalog=Test;Data Source=Server"
        Adodc1.ConnectionTimeout = 0
        Adodc1.CommandType = adCmdText
        Adodc1.CursorLocation = adUseClient
        Adodc1.CursorType = adOpenStatic
        Adodc1.LockType = adLockOptimistic
    End Sub