Reputation: 1
i have list of text file i need to select the contain and importing it to sql, when excel sheet i did it, but with text file it give me error "C:\CETS\filename.TXT' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides." my code.
string strconn1 = "Provider=Microsoft.Jet.OLEDB.4.0;"
+ "Data Source="
+ p_Excel_Path1
+ ";Extended Properties='text;HDR=Yes;FMT=Delimited(,)'";
cmdOledb2.CommandText = "select * from [Sheet1$]";
Upvotes: 0
Views: 1296
Reputation: 53595
To connect to a text file data source using OLEDB 4.0 your connection string's data source parameter needs to specify the full name of the folder your text file is in, not the text file itself. Your SELECT statement will specify the text file name.
So in your assignment to strconn1
, have your p_Excel_Path1
variable set to C:\CETS\
and change your SELECT statement to:
select * from [filename.TXT]
Upvotes: 2