Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 OLEDB to import from CSV file without extension

Author  Topic 

leezo
Starting Member

9 Posts

Posted - 2009-08-23 : 11:04:16
Hi,

I am using OLEDB to import data from a CSV file into my database. The code works great as long as the file has a .CSV extension. My problem is that it fails if the file has no extension which is the actual case in my files.

Here is my code:


Dim strProvider As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\;Extended Properties='text;HDR=Yes;FMT=Delimited'"

Dim csvConn As New System.Data.OleDb.OleDbConnection
Dim MyDS As System.Data.DataSet = New System.Data.DataSet

MyCmd = New System.Data.OleDb.OleDbDataAdapter("Select * from flagfile1374883499", csvConn)
MyCmd.TableMappings.Add("Table", "TestTableName")
MyCmd.Fill(MyDS)



This works if you add a .CSV, otherwise an exception is thrown when I try to fill the database. saying (Cannot update. Database or object is read-only.)

I assume the OLEdb object is looking for the default value which is the filename.txt? What do you think?
   

- Advertisement -