vb.net conection string to C# -- problem

R

Rich P

Here is the oledb connection string which works fine in VB.Net

connOle.ConnectionString = _
& "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=C:\;Extended " _
& "Properties=""text;"HDR=Yes;FMT=TabDelimited"""

I am having problems with the doublde quotes inside the string
..."Properties = ""...""" part. Here is what I tried that is not
working:

connOle.ConnectionString =
+ "Provider=Microsoft.Jet.OLEDB.4.0;"
+ "Data Source=C:\\;"
+
"Extended Properties="""text;HDR=Yes;FMT=TabDelimited"""";

Here is the string unparsed:

connOle.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\;Extended Properties="""text;HDR=Yes;FMT=TabDelimited"""";

C# is not liking the inner double quotes. How do I handle this?

Thanks

Rich
 
R

Rich P

I think I handled it. I escaped the inner double quotes with a
backslash before each double quote. C# stopped complaining. Now I just
hope my thing runs.

Rich
 
A

Arne Vajhøj

Here is the oledb connection string which works fine in VB.Net

connOle.ConnectionString = _
& "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=C:\;Extended " _
& "Properties=""text;"HDR=Yes;FMT=TabDelimited"""

I am having problems with the doublde quotes inside the string
.."Properties = ""...""" part. Here is what I tried that is not
working:

connOle.ConnectionString =
+ "Provider=Microsoft.Jet.OLEDB.4.0;"
+ "Data Source=C:\\;"
+
"Extended Properties="""text;HDR=Yes;FMT=TabDelimited"""";

Here is the string unparsed:

connOle.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\;Extended Properties="""text;HDR=Yes;FMT=TabDelimited"""";

C# is not liking the inner double quotes. How do I handle this?

VB.NET "bla "" bla" can be done in C# as "bla \" bla" and
@"bla "" bla".

Arne
 
J

Jeff Johnson

VB.NET "bla "" bla" can be done in C# as "bla \" bla" and
@"bla "" bla".

The extra warning being that if you use the @"..." syntax you lose ALL
backslash escape sequences, so you can't directly include tabs, for example.
 
A

Arne Vajhøj

The extra warning being that if you use the @"..." syntax you lose ALL
backslash escape sequences, so you can't directly include tabs, for example.

If your editor supports it then you can enter a literal tab
in the string.

I will not recommend it though.

Arne
 
S

Scott M.

Did you get rid of the first + sign? It's used to concatenate strings, but
there is no need to use it prior to the start of the string.

-Scott
 
A

Adam Davis

Try this

connOle.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; "
+ "Data Source=C:\" + "; Extended
Properties="+"text;"+"HDR=Yes;FMT=TabDelimited";
 

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