Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to make SQL Compact file path selection dynamic so user would select their own file.
I can get user's selected file path using following code:
C#
private void FilePath_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            if (openFileDialog1.ShowDialog()==DialogResult.OK)
            {
                string strText = openFileDialog1.FileName;
                txtPath.Text = strText;
            }
        }

But I have no idea about how to use the grabbed file path (in a textbox) as a SQL data table file path.
Please guide me. My current SQL data table code (static) is:
C#
SqlCeConnection myConnection = new SqlCeConnection();
            myConnection.ConnectionString = @"Data Source=C:\Users\Dell\Desktop\DataGridView\PMinfo.sdf";


What I have tried:

C#
SqlCeConnection myConnection = new SqlCeConnection();
            myConnection.ConnectionString = @"Data Source=C:\Users\Dell\Desktop\DataGridView\PMinfo.sdf";
Posted
Updated 25-Nov-20 8:01am
v2

1 solution

Try:
C#
SqlCeConnection myConnection = new SqlCeConnection();
myConnection.ConnectionString = $"Data Source={txtPath.Text}";
 
Share this answer
 

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