How to replace '/' to '//' in database path,after selecting it from openfiledialog() control.
From

OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:[B]\[/B]Documents[B]\[/B]Visual Studio 2008[B]\[/B]WebSites[B]\[/B]myproject[B]\[/B]db[B]\[/B]mobile.mdb");

To

OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:[B]\\[/B]Documents[B]\\[/B]Visual Studio 2008[B]\\[/B]WebSites[B]\\[/B]myproject[B]\\[/B]db[B]\\[/B]mobile.mdb");

using button click

Recommended Answers

All 3 Replies

No need to replace backslashes. For string literal we need to add \\ (backslashes). However you can use String.Replace() method.

No need to replace backslashes. For string literal we need to add \\ (backslashes). However you can use String.Replace() method.

Thanks for reply,I tried it but shows error in "\\".Pl resolve it.

string p1=textBox4.Text .ToString().Replace("\","\\");
                 MessageBox.Show(p1);

Hi, adobe71.
C# uses the backslash to escape characters, so "\\" is equal to \ literal, and "\" results in error, because you trying to escape the second quote and your string literal remains "unclosed".

You have 2 ways to go:
1. As you can see, double backslash results in a single one. So, to have \ ? you have to write \\ . 4 backslashes to result "\\" .. and so on.

2. You can use @ before your string literal, so the compiler won't try to get the control sequences from your string (based on the backslashes) and would treat your string same, as you write it (so the @"\" results into \ ).

commented: Good advice! +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.