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.
Access DataBase Source
Page 1 of 15 Replies - 1205 Views - Last Post: 15 March 2013 - 12:17 PM
Replies To: Access DataBase Source
#2
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.
"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.
#4
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
#5
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.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|