PC Review


Reply
Thread Tools Rate Thread

Comma Delimited File & Microsoft.Jet.OLEDB.4.0 provider

 
 
TF
Guest
Posts: n/a
 
      23rd Feb 2004
Hi,
I have to access data from a comma delimited file in .net windows
application (VB.net or C#). I am using Microsoft.Jet.OLEDB.4.0
provider for this purpose. Now the problem is when i extract data from
a file with extension csv or txt it works fine but as soon as i change
the extension, like 'log' or 'abc' it gives following error in 'Fill'
function of 'OleDbDataAdapter':

Cannot update. Database or object is read-only

I've added file entry in 'schema.ini' file, also I've created a dummy
System DSN and added new extension 'log' in it, but no success.

Here is the code:

//--------------------------------------------
string strConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\data\\; Extended Properties=\"Text;HDR=YES;\"";

// open connection
OleDbConnection oCon = new OleDbConnection(strConString);
oCon.Open();

// fill data set
string strSql = "SELECT * FROM datafile.txt";
OleDbDataAdapter oDA = new OleDbDataAdapter( strSql, oCon );
DataSet oData = new DataSet();
oDA.Fill( oData, datafile.txt ); // -- error if file extension is
log

oCon.Close();
//---------------------------------------------

Any help??
TF
 
Reply With Quote
 
 
 
 
Cor
Guest
Posts: n/a
 
      23rd Feb 2004
Hi TF,

Can you look at this sample I have made.
The delimiter has to be in your culture setting standard otherwise you have
to play with it.

I hope this helps?

Cor
\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim file As String = "Test2.txt"
Dim path As String = "C:\"
Dim ds As New DataSet
Try
Dim f As System.IO.File
If f.Exists(path & file) Then
Dim ConStr As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
path & ";Extended Properties=""Text;HDR=No;FMT=Delimited\"""
Dim conn As New OleDb.OleDbConnection(ConStr)
Dim da As New OleDb.OleDbDataAdapter("Select * from " & _
file, conn)
da.Fill(ds, "TextFile")
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
DataGrid1.DataSource = ds.Tables(0)
End Sub
///


 
Reply With Quote
 
TF
Guest
Posts: n/a
 
      24th Feb 2004
Thanks Cor
 
Reply With Quote
 
Paul Clement
Guest
Posts: n/a
 
      24th Feb 2004
On 23 Feb 2004 06:33:01 -0800, (E-Mail Removed) (TF) wrote:

¤ Hi,
¤ I have to access data from a comma delimited file in .net windows
¤ application (VB.net or C#). I am using Microsoft.Jet.OLEDB.4.0
¤ provider for this purpose. Now the problem is when i extract data from
¤ a file with extension csv or txt it works fine but as soon as i change
¤ the extension, like 'log' or 'abc' it gives following error in 'Fill'
¤ function of 'OleDbDataAdapter':
¤
¤ Cannot update. Database or object is read-only
¤
¤ I've added file entry in 'schema.ini' file, also I've created a dummy
¤ System DSN and added new extension 'log' in it, but no success.
¤
¤ Here is the code:
¤
¤ //--------------------------------------------
¤ string strConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
¤ Source=C:\\data\\; Extended Properties=\"Text;HDR=YES;\"";
¤
¤ // open connection
¤ OleDbConnection oCon = new OleDbConnection(strConString);
¤ oCon.Open();
¤
¤ // fill data set
¤ string strSql = "SELECT * FROM datafile.txt";
¤ OleDbDataAdapter oDA = new OleDbDataAdapter( strSql, oCon );
¤ DataSet oData = new DataSet();
¤ oDA.Fill( oData, datafile.txt ); // -- error if file extension is
¤ log
¤
¤ oCon.Close();
¤ //---------------------------------------------


By default the Text ISAM driver is only set up to support specific file extensions. Modifying the
Registry or renaming the file temporarily will resolve the issue. See the following MS KB article
for more info:

ACC2000: Importing or Linking a Text File Fails for a File That Does Not Have a Valid File Name
Extension
http://support.microsoft.com/default...b;en-us;304206


Paul ~~~ (E-Mail Removed)
Microsoft MVP (Visual Basic)
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the l =?Utf-8?B?aGVucnk=?= Microsoft Excel Programming 0 6th Dec 2006 03:38 AM
Provider=Microsoft.Jet.OLEDB.4.0 =?Utf-8?B?ZHNob3J0MTIyNQ==?= Microsoft Windows 2000 1 11th Mar 2006 04:13 AM
delimited, but Non-Comma Delimited file, for input. Ross.prillaman@HCAhealthcare.com Microsoft Access External Data 1 15th Aug 2005 05:55 PM
SqlException: Could not create an instance of OLE DB provider 'Microsoft.Jet.OLEDB.4.0' Evan Camilleri Microsoft ADO .NET 6 23rd Apr 2005 10:10 AM
How do I save microsoft excell files back to comma delimited file. =?Utf-8?B?ZW1pY2hl?= Microsoft Excel Worksheet Functions 7 23rd Oct 2004 05:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:42 PM.