i have a form that edits contents in a database. everything is correct to my point of view but when i try to update a path of an image it gives me an error telling me

System.Data.OleDb.OleDbException was unhandled
Message="Incorrect syntax near 'C:'."
Source="Microsoft OLE DB Provider for SQL Server"
the rest is the stack trace

i want to save a path which looks something like this:
C:\Users\Neville\Desktop\ThunderBolt Technologies Ltd\ThunderBolt Technologies Ltd\bin\Debug\Items\Item 11.jpg
when i debug the program it shows me that the \ becomes \\ for example C:\\Users\\ and so on(i dont know why) and then i tried using a foreach loop to get the whole imagePath put it in a charArray and when i hit \\ i use the .Replace function to turn it into / which is a readable string as \ or \\ are i think escape characters.

All in all if i could i would like to store the path using the ~ instead of the Application.StartUpPath which will save me many problems. any hints on this? thanks

When you specify a path in a string in code that contains the backslash character, you must "escape" it. So, if you want to save a file named "gunk.txt" to the root of the C: drive, you would have to type:

string sPath = "C:\\gunk.txt";

That will be suitable for using in a function that takes a file/path string.

yes but i need to remove to C:\\ thing and put a universal letter which is ~ so when i install the program on another computer on a hard drive G:\ no errors come up when getting the product from the database. i need to remove the \ thing

"~" in Windows won't work (unless you are doing this in Mono, on Linux?)

In the framework, there is an enumeration of "special folders", the items like "My Documents", "MyPictures", etc. You use it like this:

Console.WriteLine("GetFolderPath: {0}",               Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));

Check out the doc - there may be something here for you to use, when you don't know the structure of the the target computer you are going to install your software onto.


In c# you can use


to give path