3 Replies - 450 Views - Last Post: 04 July 2012 - 03:42 AM Rate Topic: -----

#1 satyadeep.k  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-June 12

Accessing login details using access in vb.net

Posted 30 June 2012 - 05:07 PM

Errors:

1.How to handle com exception?
Here is the attachment of the error... (1st attachment)Attached Image

2.Is there any way to convert .accdb file to .mdb or .mdf?Attached Image
(2nd attachment)

Code:

Public Class Form2


    Dim loginerror As String

    Public Function Login()

        Dim DBConn As New ADODB.Connection

        Dim User As New ADODB.Recordset

        Dim Username As String
        Dim userDB As String
        Dim passDB As String

        Dim UserFound As Boolean


        DBConn.Open("Provider = Microsoft.Jet.OLEDB.4.0;" & _
                     "Data Source = '" & Application.StartupPath & "\LoginDatabase.mdb'")


        User.Open("LoginTable", DBConn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

        UserFound = False
        Login = False
        Username = "Username = '" & TextBox1.Text & "'"

        Do
            User.Find(Username)

            If User.BOF = False And User.EOF = False Then
                userDB = User.Fields("Username").Value.ToString

                passDB = User.Fields("Password").Value.ToString

                If userDB <> TextBox1.Text Then
                    User.MoveNext()
                Else
                    UserFound = True
                    If passDB = TextBox2.Text Then
                        User.Close()
                        DBConn.Close()
                        Return True
                    Else
                        loginerror = "Invalid Password"
                        User.Close()
                        DBConn.Close()
                        Return False

                    End If
                End If
            Else
                loginerror = "Invalid Username"
                User.Close()
                DBConn.Close()
                Return False

            End If
        Loop Until UserFound = True

        User.Close()
        DBConn.Close()
        Return False


    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Login() = True Then
            MessageBox.Show("Logged In.!!", "Login Message")
        Else
            MessageBox.Show(loginerror, "Login Message")
        End If
    End Sub
End Class



Requirement:

To create a login form which checks the username and password fields from the database.

Is This A Good Question/Topic? 0
  • +

Replies To: Accessing login details using access in vb.net

#2 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,053
  • Joined: 17-July 10

Re: Accessing login details using access in vb.net

Posted 01 July 2012 - 01:56 AM

1. The error is quite expressive: you put the wrong path to your database. As I see from second attachement, you have LoginDatabase within a folder called Database. Instead of Application.StartupPath & "\LoginDatabase.mdb" put the absolute path to the database(hardcoded). If it works, find another way to give the path(maybe through an app.config file). Also, make sure the extension is mdb and not accdb.

2. Create script files for creating and inserting data into a mdb or mdf(sql script files) and rebuild your database. Propably there are softwares somewhere on the internet that do this, but I'm not sure what you are looking for.
Was This Post Helpful? 1
  • +
  • -

#3 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 135
  • Joined: 19-May 12

Re: Accessing login details using access in vb.net

Posted 01 July 2012 - 07:51 AM

DBConn.Open("Provider = Microsoft.Jet.OLEDB.4.0;" & _
	                     "Data Source = '" & Application.StartupPath & "\LoginDatabase.mdb'")



This is your error

Now replace that line with something like this as you have .accdb file

DBConn.Open("Provider = Microsoft.Ace.OLEDB.12.0;" & _
	                     "Data Source = '" & Application.StartupPath & "\LoginDatabase.accdb'")



In the above line i have done three replacements
1) Ace instead of Jet 'Because Jet is no more supported with MS-Access 2007 and above
2) 12.0 instead of 4.0 'Because 12.0 is used with Ace
3).accdb instead of .mdb

Mark this post as helpful if it helps you
Was This Post Helpful? 0
  • +
  • -

#4 Bort  Icon User is offline

  • No bunnies were harmed in the cloning of this Bort
  • member icon

Reputation: 214
  • View blog
  • Posts: 2,231
  • Joined: 18-September 06

Re: Accessing login details using access in vb.net

Posted 04 July 2012 - 03:42 AM

Vishal, if the OP is using an earlier version of Access (as in, not Access 2007), then everything you said is wrong.

DBConn.Open("Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source = '" & Application.StartupPath & "\Database\LoginDatabase.mdb'")



This might work, but it assumes that when your application is compiled, your entire 'Database' folder is copied into the output folder (depending on whether you get your database file converted, you may need to change the last part of the filepath to LoginDatabase.accdb). You may also want to consider copying your Database folder into your project's bin\debug folder. You can't test how your project accesses your database if your database isn't in the right place.

I'm unsure of how to convert your accdb file into an mdb file, but it seems that accdb is the standard file format for Access 2010, and mdb is the file format for older versions of Access. If you have a recent version of Access, it should just be a case of loading the accdb file and saving it again as an mdb.
Was This Post Helpful? -1
  • +
  • -

Page 1 of 1