Click here to Skip to main content
15,883,945 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi !

I have to use Excel from Diffrent Location not Fix Location.Like C:\Details.xls.
MSIL
string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Details.xls;Extended Properties=""Excel 8.0;HDR=YES;""";


I am trying but not work ---
string FPath = "C:\Details.xls";
MSIL
string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+ FPath  +";Extended Properties=""Excel 8.0;HDR=YES;""";


Please Correct it.

As I am using Paramereized Code below, it is working Fine(Database path passing from TextBox) ---
string str = "INSERT INTO Test SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=" + txtPath.Text + "', 'SELECT * FROM [Details$]')";
Posted

Shouldn't

string FPath = "C:\Details.xls";


be

string FPath = @"C:\Details.xls";


?

Cheers
 
Share this answer
 
Stick an '@' character in front of the double quotes:
string FPath = @"C:\Details.xls";

That stops the C# compiler assuming "\D" is a single escaped character...
 
Share this answer
 
VB
Sir,

I am using but not Work ---
string _FileName = FileImageC.PostedFile.FileName;
//Physical Path Return :C:\Documents and Settings\PP_2\My Documents\Details.xls

string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=@_FileName;Extended Properties=""Excel 8.0;HDR=YES;""";
 
Share this answer
 
Comments
Estys 27-Aug-10 8:28am    
@_Filename isn't going to work, this isn't a scripting language.
You should use ... Data Source =" + _FileName + ";Extended ... etc.
Maybe it's even necessary to put qoutes around your filename because it has space characters in it.
LebneizTech 27-Aug-10 8:37am    
I had Check it, but not work

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900