CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2002
    Location
    Australia
    Posts
    6

    Question reading from database

    Hi All,

    could some one please let me know how to open database(Access) and check for login name and password from the user table at runtime. I want to check for all the available users in the table.

    Thanks and regards
    Ram

  2. #2
    Join Date
    Aug 2001
    Posts
    1,447
    this should do it for you. as commented in the code, there are two techniques and I've only gotten one of them to work, but it should do what you want.
    Attached Files Attached Files
    phinds
    vs2008, 3.5SP1 Version 9.0.21022.8 RTM

  3. #3
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210
    Following is an example of opening and reading a Access Database table.
    You will need to make several modifications to get it to work with your DataBase. Review the comments and make adjustments as necesary.
    Code:
    Option Explicit
    ' Set a reference to "Microsoft ActiveX Data Object 2.5 LIbrary"
    ' Add a Listbox to the Form
    ' Add a command button to the Form
    Dim AccessConnect As String
        Dim Conn1 As ADODB.Connection
        Dim Cmd1 As ADODB.Command
        Dim Params1 As ADODB.Parameters
        Dim Param1 As ADODB.Parameter
        Dim Rs1 As ADODB.Recordset
    
    Private Sub Command1_Click()
        ' following statement has the following requirements
        ' 1. DBQ = DataBase name
        ' 2. DefaultDir is its location
        AccessConnect = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
                        "DBQ=ADODEMO.MDB;" & _
                        "DefaultDir=C:\VB Stuff\ADO Example (MSDN);" & _
                        "UID=admin;PWD=;"
        Set Conn1 = New ADODB.Connection
        Conn1.ConnectionString = AccessConnect
        Conn1.Open
        Set Cmd1 = New ADODB.Command
        Cmd1.ActiveConnection = Conn1
        ' The following statement Selects the table
        Cmd1.CommandText = "SELECT * FROM Authors "
       
        Set Param1 = Cmd1.CreateParameter(, adInteger, adParamInput, 3)
        Param1.Value = 10
        Cmd1.Parameters.Append Param1
        Set Param1 = Nothing
       
        Set Rs1 = Cmd1.Execute()
        While Rs1.EOF = False
        ' The following will access the individual records and add
        ' appropriate data to the listbox
            List1.AddItem vbTab & Rs1.Fields(0).Value & " | " & _
                          Rs1(1).Value & " | " & _
                          Rs1("Year Born")
            Rs1.MoveNext
        Wend
        Conn1.Close
        
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured