5 Replies - 2311 Views - Last Post: 15 March 2013 - 12:17 PM Rate Topic: -----

#1 faisalmukhtarch  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 06-October 12

Access DataBase Source

Posted 15 March 2013 - 08:20 AM

i am using "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\My PC\Desktop\MOMS 3\MOMS2\WindowsApplication2\MOMS.accdb" This is the path to connect with the database. can you one tell me any other way i can use instead of this. I want to use the program on other computers. I tried "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|Data Directory|\MOMS.accdb"
but it didn't help.
Is This A Good Question/Topic? 0
  • +

Replies To: Access DataBase Source

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1606
  • View blog
  • Posts: 5,163
  • Joined: 25-September 09

Re: Access DataBase Source

Posted 15 March 2013 - 08:50 AM

You can store the database with the executable and use
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & application.startuppath & "\MOMS.accdb"

Which would always look for the database in the folder that the exe is in.

You could let the user locate the database (in case they have a network share that they keep all these things in) and store that path somewhere where you can access it and use to connect.
Was This Post Helpful? 0
  • +
  • -

#3 faisalmukhtarch  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 06-October 12

Re: Access DataBase Source

Posted 15 March 2013 - 11:41 AM

same problem
Was This Post Helpful? 0
  • +
  • -

#4 faisalmukhtarch  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 06-October 12

Re: Access DataBase Source

Posted 15 March 2013 - 11:52 AM

Imports System.Data
Imports System.Data.OleDb
Public Class Main_Login
    Dim cn As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\My PC\Desktop\MOMS 3\MOMS2\WindowsApplication2\MOMS.accdb")
    Dim sql As String
    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Application.Exit()

    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        Dim reader As OleDbDataReader
        sql = "SELECT * FROM Staff WHERE StaffID=@staffid and Password=@password" '& txtStaffID.Text & "' AND Password='" & txtPassword.Text & "'"

        cn.Open()
        Dim cmd As OleDbCommand = New OleDbCommand(sql, cn)
        cmd.Parameters.AddWithValue("StaffID", txtStaffID.Text)
        cmd.Parameters.AddWithValue("Password", txtPassword.Text)

        reader = cmd.ExecuteReader
        If reader.HasRows = True Then
            MessageBox.Show("Logged in", "Login Successful", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Main_Menu.Show()

        Else
            MessageBox.Show("Incorrect username or password", "Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End If
        reader.Close()
        cn.Close()


    End Sub

    Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Registery_Form.Show()
        Me.Hide()

    End Sub

    Private Sub btnRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRegister.Click
        Me.Hide()
        Registery_Form.Show()
    End Sub
End Class

When i am using the following code i can login. but when i change it to "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & application.startuppath & "\MOMS.accdb"

I get the incorrect User Name or Password Error
Was This Post Helpful? 0
  • +
  • -

#5 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1606
  • View blog
  • Posts: 5,163
  • Joined: 25-September 09

Re: Access DataBase Source

Posted 15 March 2013 - 12:01 PM

Application.StartupPath returns the path that the EXECUTABLE was executed in. Right now, I'm willing to bet that if you looked in that folder (where MOMS.accdb is) that you wouldn't find your executable for your application. Instead I'm going to bet that it resides in the WindowsApplication2\Bin\Debug folder (possibly release as I don't know your settings) but if you were to move that database into that debug folder where the executable resides, and try it again I'm sure it would work.
Was This Post Helpful? 0
  • +
  • -

#6 faisalmukhtarch  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 06-October 12

Re: Access DataBase Source

Posted 15 March 2013 - 12:17 PM

It works. Thanks a lot
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1