vb.net conection string to C# -- problem

  • Thread starter Thread starter Rich P
  • Start date Start date
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
 
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
 
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
 
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.
 
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
 
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
 
Try this

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