Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

75 views
Skip to first unread message

TF

unread,
Feb 23, 2004, 9:33:01 AM2/23/04
to
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

Cor

unread,
Feb 23, 2004, 10:17:22 AM2/23/04
to
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
///


TF

unread,
Feb 24, 2004, 7:46:54 AM2/24/04
to
Thanks Cor

Paul Clement

unread,
Feb 24, 2004, 3:46:56 PM2/24/04
to
On 23 Feb 2004 06:33:01 -0800, far...@coned.com (TF) wrote:

¤ Hi,


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.aspx?scid=kb;en-us;304206


Paul ~~~ pcle...@ameritech.net
Microsoft MVP (Visual Basic)

0 new messages