Click here to Skip to main content
15,889,346 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm making a database software where i want to give people the choice where to put the database (such as a central nas location or a server) in order to have the software on 2 or more computers.
Therefore I made code to choose a database location in the initial startup form.
The code for this is:

VB
System.Data.OleDb
Public Class LoginScreen

    'DEEL 1: HIER KOMT DATABASE CODE
    Private Sub Loginscreen_load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'PatientendatabaseDataSet1.tbl_users' table. You can move, or remove it, as needed.
        pnlLoginPanel.Visible = False

    End Sub
    Private Sub btnChoose_Click(sender As Object, e As EventArgs) Handles btnChoose.Click
        Dim strtext As String
        OpenFileDialog1.Filter = "Database Files | *.mdb"
        OpenFileDialog1.InitialDirectory = "F:\GoogleDrive\EINDWERK VBNET"
        OpenFileDialog1.Title = "Choose your Database"
        OpenFileDialog1.ShowDialog()
        strtext = OpenFileDialog1.FileName
        txtDatabaselocationshow.Text = strtext

    End Sub
    Private Sub btnDBConnect_Click(sender As Object, e As EventArgs) Handles btnDBConnect.Click
        If txtDatabaselocationshow.Text = "" Then
            MessageBox.Show("Please choose a database!")
            chkRememberDB.Checked = False
        Else
            pnlLoginPanel.Visible = True

        End If
    End Sub
    Private Sub chkRememberDB_CheckedChanged(sender As Object, e As EventArgs) Handles chkRememberDB.CheckedChanged
        If chkRememberDB.Checked = True Then
            txtDatabaselocationshow.ReadOnly = True
        Else
            txtDatabaselocationshow.ReadOnly = False
        End If
    End Sub


so as soon as i press "connect" in the form i should connect to the database.

In the future forms in my software , is there a way to replace the "actual location" with the string that's displayed in the selected textbox field?

What I have tried:

so instead of
VB
Provider=Microsoft.ACE.OLEDB.12.0;Data Source="F:\GoogleDrive\EINDWERK VBNET\PatientenDatabase.accdb"


it can show something like this?
VB
Using conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=strtext")
Posted
Updated 8-Nov-20 23:43pm
v2

1 solution

Set the location as a format string:
VB
Dim base As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=""{0}"""
Dim strConnect As String = String.Format(base, strtext)
 
Share this answer
 
Comments
Izzy Decorte 7-Nov-20 15:15pm    
Hello Griff, thanks for the quick reply.
just to make sure: the syntax further on goes like this?
Dim base As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=""{0}"""
Dim strConnect As String = String.Format(base, strtext)
Try
Using conn As New OleDbConnection("strConnect")
conn.Open()...
or do i lose the quotes?
OriginalGriff 7-Nov-20 15:45pm    
Yes, lose the quotes ... you do know the difference between constant and variables, don't you? Because if you don't, then you really need to go back to the beginning of your course and start all over again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900