Whats wrong with this line?

  • Thread starter Thread starter Ruslan Shlain
  • Start date Start date
R

Ruslan Shlain

I cant get this to work in C#. It works in VB.NET.

OleDbConnection Conn = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FilePath +
";Extended Properties=""text;HDR=NO;FMT=Delimited""");



FilePath = "C:\\ftproot\\TOG\\"
 
Ruslan said:
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
FilePath + ";Extended Properties=""text;HDR=NO;FMT=Delimited""");

Try this:

OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
FilePath + ";Extended Properties=\"text;HDR=NO;FMT=Delimited\"");

Note the escaped double quotes.
 
This worked just fine. Thank you. I am very new to C#. Its my first day. Why
did i have to use the \ ?
 
Ruslan said:
This worked just fine. Thank you. I am very new to C#. Its my first
day. Why did i have to use the \ ?

That is how you place normally "illegal" characters in a string. For
example, you had to use \\ instead of \ in your string because using a
single \ gave you an error.

You could also say something like a = @"c:\t\1\2\3" without a problem
because the @ tells c# that you are not using excape sequences, so it
does not require double backaslashes.

There are several other escape sequences, for example \r\n for a carriage
return/life feed pair. You should read up on these, they are powerful to
use.

Glad to help.
 
Back
Top