Hi All,
I seem to be having difficulty inserting a variable in the middle of my connection string. Seems it should be easy enough but I have tried many different ways. I am uploading an excel sheet and at this point have the path hard coded. I want to use a variable for the path. Here is the string.
string ExcelconnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= D:\Debug\Draft company_Oilco9.xls;Extended Properties=""Excel 8.0;HDR=YES;""";
Here is what I tried that didn't work
string ExcelconnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" text";Extended Properties=""Excel 8.0;HDR=YES;""";
Any help is appreciated
AlanPosted Nov 16, 2008, 1:00 PM
You also need an @ preceding the final string because of the use of the doubled double-quotes which isn't allowed in a 'normal' string:
string ExcelconnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + text + @";Extended Properties=""Excel 8.0;HDR=YES;""";
AlanPosted Nov 16, 2008, 2:18 PM
George LaingPosted Nov 16, 2008, 1:11 PM
George LaingPosted Nov 16, 2008, 11:18 AM
Hi,
I tried your line and I get basically the same problem as I had with the line I tried. the part of the string below is underlined and I ger "; expected". As I say it seems to be trickier than expected.
"Excel 8.0;HDR=YES;"""
Ryan AlfordPosted Nov 16, 2008, 11:08 AM
string ExcelconnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + text + ";Extended Properties=""Excel 8.0;HDR=YES;""";