Whats wrong with this line?

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\\"
 
G

gabriel

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.
 
R

Ruslan Shlain

This worked just fine. Thank you. I am very new to C#. Its my first day. Why
did i have to use the \ ?
 
G

gabriel

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top