HDR=NO yet first row appears as headers

  • Thread starter Thread starter jeff via .NET 247
  • Start date Start date
J

jeff via .NET 247

I'm using the following connection string to read in a CSV...
OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + fileInfo.DirectoryName + ";" + @"Extended Properties=""text;HDR=NO;FMT=Delimited""");

and the rest of my code being pretty close in structure to the CSV reader Don XML posted on his blog here:
http://weblogs.asp.net/donxml/archive/2003/08/21/24908.aspx

I've tried various incarnations and incantations but have yet to read the first row of the CSV as anything other than column headers. Suggestions?

thanks in advance,
j
 
Hi,

Do you have Schema.ini file? If yes, then check if you did not specify that
file has a header inside of the Schema.ini
 
Hi Val

no I don't have a Schema.ini --- I actually want to specify that I don't
have a header in my files.

j

Val Mazur said:
Hi,

Do you have Schema.ini file? If yes, then check if you did not specify that
file has a header inside of the Schema.ini
 
Jeff,

ADO is going to need a name for each of the fields of the recordset that is
constructed -- specifying HDR=NO works only if you supply the field names -
either explicitly or via the schema.ini file.

have a look at the following link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnclinic/html/scripting03092004.asp

regards
roy fine


jeff via .NET 247 said:
I'm using the following connection string to read in a CSV...
OleDbConnection connection = new
OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + fileInfo.DirectoryName + ";" + @"Extended Properties=""text;HDR=NO;FMT=Delimited""");

and the rest of my code being pretty close in structure to the CSV reader
Don XML posted on his blog here:
http://weblogs.asp.net/donxml/archive/2003/08/21/24908.aspx

I've tried various incarnations and incantations but have yet to read the
first row of the CSV as anything other than column headers. Suggestions?
 
Roy,

thanks a bunch, now it makes sense. So now off to figure out how to
dynamically generate a schema.ini for each csv

thanks again
j

Roy Fine said:
Jeff,

ADO is going to need a name for each of the fields of the recordset that is
constructed -- specifying HDR=NO works only if you supply the field names -
either explicitly or via the schema.ini file.

have a look at the following link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnclinic/html/scripting03092004.asp

regards
roy fine


jeff via .NET 247 said:
I'm using the following connection string to read in a CSV...
OleDbConnection connection = new
OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + fileInfo.DirectoryName + ";" + @"Extended Properties=""text;HDR=NO;FMT=Delimited""");

and the rest of my code being pretty close in structure to the CSV reader
Don XML posted on his blog here:
http://weblogs.asp.net/donxml/archive/2003/08/21/24908.aspx

I've tried various incarnations and incantations but have yet to read the
first row of the CSV as anything other than column headers. Suggestions?
 
¤ I'm using the following connection string to read in a CSV...
¤ OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;" +
¤ "Data Source=" + fileInfo.DirectoryName + ";" + @"Extended Properties=""text;HDR=NO;FMT=Delimited""");
¤
¤ and the rest of my code being pretty close in structure to the CSV reader Don XML posted on his blog here:
¤ http://weblogs.asp.net/donxml/archive/2003/08/21/24908.aspx
¤
¤ I've tried various incarnations and incantations but have yet to read the first row of the CSV as anything other than column headers. Suggestions?
¤

I think you have a misunderstanding as to how the HDR argument operates.

The setting must be HDR=YES if the first row of your text file contains the column header names.
Otherwise, using HDR=NO, the first row is assumed to contain actual data.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
¤ thanks for the response Paul, I don't think I misunderstood just possibly
¤ miscommunicated! ;-)
¤
¤ I want the first row of data regardless of whether it is a header or not,
¤ hence the setting of NO. I can't go the schema.ini route due to the fact that
¤ there is no standard or common structure to the csv files I'm handling.

Not sure what to tell you. If some files contain headers and some don't, the bottom line is that you
have to have some way to distinguish between the two, either before or after they're queried.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Schema.ini Not Required

I experienced this same issue. Although this post is two years old, I thought I would respond anyway in case someone else ends up here with the same issue.

I did not want to use a schema.ini as my file names are always changing. Just wanted to import all of the records of my comma separated file with no header, but received errors when I tried the HDR=No. If I left out the HDR=No, the first record of my csv file was missing in my dataset. I then found this article by microsoft ...

http://support.microsoft.com/kb/257819

Search for hdr=no. This is a syntax thing. This is my connection string that allows me to import all the records in my csv file without a schema.ini.

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & pstrFolderName & ";Extended Properties=""Text;HDR=No;"""

Notice the extra quotes.

Hope this helps somebody.
 
Back
Top