CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2000
    Location
    Israel,tel-aviv
    Posts
    25

    username and password -access database

    hello, Im having problem with accessing Access DB with username and password, I used an sql statement but it doesnt work...do you know the code to enter to A Database with username and password??

    this is the code i wrote:

    Private Sub Form_Load()
    ' connecting the DB and the table

    strFileName = App.Path & "\mydatabase.mdb"
    Set db = OpenDatabase(strFileName)
    Set rs_lgn = db.OpenRecordset("login")
    pswrd = rs_lgn![password]
    usrnme = rs_lgn![UserName]

    End Sub

    and on the click button i wrote:
    sqlstr = "SELECT * FROM rs_lgn WHERE usrnme =" & username_inpt_local & "AND pswrd = " & password_inpt_local

    'Set rs_lgn_true = db.OpenRecordset("sqlstr")

    and so on.. but it doesnt work..
    thank you


    Eli

  2. #2
    Join Date
    Feb 2001
    Posts
    54

    Re: username and password -access database

    Hello elik:

    I would access ADO. To do this, first go to Project and then Components and check Microsoft ADO. Then select Microsoft OLE for DB Provider for Oracle or SQL Provider. Next type this line of code

    Adodc1.ConnectionString = "Provider=MSDAORA. 1;Password=" & Text2.Text & ";User ID=" & Text1.Text & ";Persist Security Info=True"
    Adodc1.CommandType = adCmdUnknown

    If you are using home computer or personal computer which I am in. You need to add server if you are networked.

    Good Luck


  3. #3
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: username and password -access database

    'connection to secure database
    Dim Cnn As ADODB.Connection
    Dim Rst As ADODB.Recordset

    'In the place where you want to establish your connection

    Dim strConnect As String
    Set Cnn = New ADODB.Connection

    'Substitute your own User IDs, Password, Data Source, and System
    'database in the connection string below
    strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Password=MyPassword;User ID=Administrator;" & _
    "Data Source=C:\AccessDBs\DB1.mdb;" & _
    "Persist Security Info=True;"

    With Cnn
    .CursorLocation = adUseClient
    .Open strConnect
    End With

    Set Rst = New ADODB.Recordset
    Rst.ActiveConnection = Cnn

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  4. #4
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: username and password -access database

    Elik,

    It looks like you have your own table which stores the USERNAME and PASSWORD. Am I right? If so, it seems that your SQL statement is not really right.

    Commonly, USERNAME and PASSWORD fields are STRING type and you've your query:

    sqlstr = "SELECT * FROM rs_lgn WHERE usrnme =" & username_inpt_local & "AND pswrd = " & password_inpt_local




    I think you're missing the single quote (') marks to denote that the field data is a STRING type. The SQL query should look like this:

    sqlstr = "SELECT * FROM rs_lgn WHERE usrnme ='" & username_inpt_local & "' AND pswrd = '" & password_inpt_local & "'"




    Hope this helps,
    -Cool Bizs

    Good Luck,
    -Cool Bizs

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