Connecting a textfile to a datagrid

  • Thread starter Thread starter motimh
  • Start date Start date
M

motimh

Could someone please show me the code (or design-time) required to use
a comma-delimited textfile as data to a datagrid?
 
Hi there,

Have a look at this blog post:

http://weblogs.asp.net/donxml/archive/2003/08/21/24908.aspx

The code is in C# but can be converted to VB.NET easily. The basic idea
is that you use the Jet engine to load the CSV file for you and then you
fill a DataSet with the results.

Once you have the DataSet you can bind it to the DataGrid like you
normally would.

Regards,
-Adam.
 
Well it almost worked. I need it to connect to ODBC textfile. I
created the string connection using the wizard at design time but it
doesn't like it.

Here is the connection string:

PageTimeout=5;MaxScanRows=8;DefaultDir=C:\TOV;FILEDSN=C:\TOV\mh\mh.dsn;DriverId=27;UserCommitSync=Yes;FIL=text;UID=admin;Driver={Microsoft
Text Driver (*.txt;
*.csv)};MaxBufferSize=2048;Threads=3;SafeTransactions=0

Here is the error message that is displayed using your code: (my file
is NOT read-only)

System.Data.Odbc.OdbcException: ERROR [42000] [Microsoft][ODBC Text
Driver] Cannot update. Database or object is read-only.
at System.Data.Odbc.OdbcConnection.HandleError(HandleRef hrHandle,
SQL_HANDLE hType, RETCODE retcode)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior
behavior, String method)
at System.Data.Odbc.OdbcCommand.ExecuteReader(CommandBehavior
behavior)
at
System.Data.Odbc.OdbcCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior
behavior)
at System.Data.Common.DbDataAdapter.FillFromCommand(Object data,
Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand
command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String
srcTable)
at WindowsApplication3.Form4.GetTxt(String FileName) in
C:\Documents and Settings\WIN2000C\My Documents\Visual Studio
Projects\WindowsApplication3\Form4.vb:line 1884
 
Mothim,

This is an OleDb feature not a ODBC feature, if it would work, than I will
be suprised.

Cor
 
Please disregard my ignorance, but I only found out now that a CSV
file IS "Comma Separated Values"; which is exactly what I need.

But when I run the code, this is my error:


System.Data.OleDb.OleDbException: Cannot update. Database or object
is read-only.
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32
hr)
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS
dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object&
executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior
behavior, Object& executeResult)
at
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior
behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior
behavior)
at
System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior
behavior)
at System.Data.Common.DbDataAdapter.FillFromCommand(Object data,
Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand
command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String
srcTable)
at WindowsApplication3.Form4.GetTxt(String FileName) in
C:\Documents and Settings\WIN2000C\My Documents\Visual Studio
Projects\WindowsApplication3\Form4.vb:line 1899




How do I change it to be not read-only?
 
Motim,

On what code?
And where this is about row 1400 or something my sample has maximum 100
lines.

The purpose is to open a new project
drag on that a datagrid
than copy and paste the code in the code of the form
set the path to your CSV file correct

And run and see

Cor
 
You are right! It was my code, because when I put it in its own
project it worked. Thank you very much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top