[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

alexbalaev

7/25/2005 1:32:00 PM

Hello,
I am trying to read an exported Event Log Viewer file saved as a CSV
with the code below and the very last line gives me "System Error".
I have Framework 1.1 (1.1.4322 SP1) and VS .NET 2003 (7.1.3088)
I would really appreciate if someone could help me to find out what's
wrong with it.
TIA, Alex.

****************************************************
string strConn = "Driver={Microsoft Text Driver (*.txt;
*.csv)};DBQ=d:\\";
string strQuery = @"SELECT * FROM applocal.csv";
OdbcConnection myConnection = new OdbcConnection(strConn);
OdbcCommand myCommand = new OdbcCommand(strQuery,myConnection);
OdbcDataAdapter adapter = new OdbcDataAdapter(myCommand);
myConnection.Open();
DataSet dtset = new DataSet();
dtset.Tables.Add("TABLE1");
adapter.Fill(dtset, "TABLE1");

5 Answers

Paul Clement

7/26/2005 1:38:00 PM

0

On 25 Jul 2005 06:32:06 -0700, alexbalaev@yahoo.com wrote:

¤ Hello,
¤ I am trying to read an exported Event Log Viewer file saved as a CSV
¤ with the code below and the very last line gives me "System Error".
¤ I have Framework 1.1 (1.1.4322 SP1) and VS .NET 2003 (7.1.3088)
¤ I would really appreciate if someone could help me to find out what''s
¤ wrong with it.
¤ TIA, Alex.
¤
¤ ****************************************************
¤ string strConn = "Driver={Microsoft Text Driver (*.txt;
¤ *.csv)};DBQ=d:\\";
¤ string strQuery = @"SELECT * FROM applocal.csv";
¤ OdbcConnection myConnection = new OdbcConnection(strConn);
¤ OdbcCommand myCommand = new OdbcCommand(strQuery,myConnection);
¤ OdbcDataAdapter adapter = new OdbcDataAdapter(myCommand);
¤ myConnection.Open();
¤ DataSet dtset = new DataSet();
¤ dtset.Tables.Add("TABLE1");
¤ adapter.Fill(dtset, "TABLE1");

I would recommend using the Jet OLEDB instead of the Text ODBC driver:

Dim ConnectionString As String

ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & "D:\" & ";" & _
"Extended Properties=""Text;HDR=No"""

Dim TextConnection As New System.Data.OleDb.OleDbConnection(ConnectionString)
TextConnection.Open()

Dim da As New System.Data.OleDb.OleDbDataAdapter("Select * from applocal.csv",
TextConnection)

Dim ds As New DataSet()
da.Fill(ds, "TABLE1")


Paul
~~~~
Microsoft MVP (Visual Basic)

alexbalaev

7/26/2005 4:26:00 PM

0

Paul,
Thanks much! It works!
I have another question if you don''t mind....
Some fields in the CSV file have new lines (carriage returns). It''s the
way how the records were exported from Event Log Viewer. When I have
such case the OLEDB cannot process the field correctly. Is there a way
to avoid the problem? Maybe I can add something to the schema.ini file?
I tried to export to TXT file - the same thing....
Thanks in advance, Alex.

shriop

7/27/2005 3:47:00 PM

0

You''re absolutely right. It looks like the Event Viewer does not export
to CSV in what is commonly known as the correct way. It''s allowing new
line characters to exist in cells, without any form of escaping or
qualifying. I don''t know of any CSV parser or importer anywhere
currently that will handle this format, including the Jet driver and
the Microsoft Text Driver. Basically, the only way logically to even
consider that data to be still in the same row is to assume a specific
column count. After seeing this, I''m pondering adding functionality to
my CSV parser to allow a forced column count. Let me know if you find
anything that can handle it that I''m unaware of, and thanks for
bringing this interesting example to light. Sorry I couldn''t help. What
you might want to consider is testing the column count on each row, and
if the column count is too low, then consider values in the next row to
be starting at the left off column.

Bruce Dunwiddie
http://www.csv...

alexbalaev@yahoo.com wrote:
> Paul,
> Thanks much! It works!
> I have another question if you don''t mind....
> Some fields in the CSV file have new lines (carriage returns). It''s the
> way how the records were exported from Event Log Viewer. When I have
> such case the OLEDB cannot process the field correctly. Is there a way
> to avoid the problem? Maybe I can add something to the schema.ini file?
> I tried to export to TXT file - the same thing....
> Thanks in advance, Alex.

alexbalaev

7/29/2005 12:58:00 PM

0

Thanks,
The fun part is this. Try to export the log file as CSV or TXT and then
"Open" it. On my XP box I get "The file is broken" something. Even MS
cannot read it!

Paul Clement

8/1/2005 3:38:00 PM

0

On 26 Jul 2005 09:26:09 -0700, alexbalaev@yahoo.com wrote:

¤ Paul,
¤ Thanks much! It works!
¤ I have another question if you don''t mind....
¤ Some fields in the CSV file have new lines (carriage returns). It''s the
¤ way how the records were exported from Event Log Viewer. When I have
¤ such case the OLEDB cannot process the field correctly. Is there a way
¤ to avoid the problem? Maybe I can add something to the schema.ini file?
¤ I tried to export to TXT file - the same thing....
¤ Thanks in advance, Alex.

Yeah, that looks rather nasty. You could try defining all the columns in a schema.ini file and
define the last column as Memo. Other than that I can''t think of anything that would fix this on the
import side.


Paul
~~~~
Microsoft MVP (Visual Basic)