I'm trying to change my connection string to w/e the user wants. After a few tips here and there, this is what I've come up:
1: In my settings I've added - Name(login), Type(String), Scope(User), Value(Nothing)
2: Here is the code I'm using
Code:Private Sub LoginForm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Here I'm checking if the login in my.settings is there 'If not, I'm going to let the user choose what database 'He/she wants strLoginPath = My.Settings.login Dim provider As String = "Microsoft.Jet.OLEDB.4.0" Dim security As String = "False" If My.Computer.FileSystem.FileExists(strLoginPath) = False Then MessageBox.Show("Stored Database path is invalid. Click OK to choose a valid Database", "System Message", MessageBoxButtons.OK) OpenFileDialog1.Filter = "Access Documents|*.mdb" OpenFileDialog1.FileName = "" OpenFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then strLoginPath = OpenFileDialog1.FileName My.Settings.login = "Provider=" & provider & _ ";Data Source =" & strLoginPath & ";Persist Security Info=" & security My.Settings.Save() Else MessageBox.Show("No Database Path selected, exiting", "Fatal Error", MessageBoxButtons.OK) End End If End If End SubThe error I get is: Format of the initialization string does not conform to specification starting at index 0.Code:Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click 'Here is my code for the login Dim con As New OleDbConnection(My.Settings.login) Dim cmd As OleDbCommand = New OleDbCommand("SELECT [First Name],password FROM login where [First Name]=? and password=?", con) cmd.Parameters.AddWithValue("username", UsernameTextBox.Text) cmd.Parameters.AddWithValue("password", PasswordTextBox.Text) Try con.Open() Dim read As OleDbDataReader = cmd.ExecuteReader() If read.HasRows Then read.Read() If UsernameTextBox.Text = read.Item("First Name").ToString And PasswordTextBox.Text = read.Item("password").ToString Then MsgBox("Login successful") SplashScreen1.Show() Me.Close() Else MsgBox("Login unsuccessful, username and passwords are case sensitive") End If Else MsgBox("Login unsuccessful") End If read.Close() Catch ex As Exception MessageBox.Show(ex.Message) Finally con.Close() End Try End Sub
here -When I have my con equal to when I added the datasource from it works. Any help?Code:Dim con As New OleDbConnection(My.Settings.login)




Reply With Quote