473,738 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading CSV into recordset using GetString

I have two(2) issues.

I'm experiencing a little difficulty and having to resort to a work around.
I already found one bug, although stated the bug was only in ODBC, which I'm
not using. It appears to be in the OLEDB driver also.

My connection was:
conn.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & strPath & ";" &
"Extended Properties='Tex t;HDR=NO;FMT=De limited'"

I got information from here:
http://msdn.microsoft.com/library/de...ng03092004.asp

I am using a schema.ini file and in it was:

[austin.csv]
Format=CSVDelim ited

Col1=personid Text
Col2=currDate Text
Col3=transCode Text
Col4=caseNum Text
Col5=caseType Text
Col6=defName Text
Col7=unknown Text

1. The first line in the csv file was being ignored, as if it was a header
line. I verified by putting a blank line in the file and then I was able to
see the first record, which was now the second line.

I read this was a bug but for FirstRowHasName s. It wasn't what I was using
but the effect was the same for HDR=NO.
"However, due to a bug in the ODBC driver, specifying the FirstRowHasName s
setting currently has no effect. In other words, the Excel ODBC driver (MDAC
2.1 and later) always treats the first row in the specified data source as
field names."

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

I found another article that fold me to use something else in the schema.ini
file:
http://www.aspdb.com/Site/tor/Manual04/T_csvtext.shtm

ColNameHeader=F alse

My current schema.ini:
[austin.csv]
Format=CSVDelim ited
ColNameHeader=F alse

Col1=personid Text
Col2=currDate Text
Col3=transCode Text
Col4=caseNum Text
Col5=caseType Text
Col6=defName Text
Col7=unknown Text

I now get the first row without the need for the blank line.

My current connection string:
conn.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & strPath & ";" &
"Extended Properties=Text "
2. I am getting a blank line using rs.GetString but at the end.

My line:
arrAccounts = split(rs.GetStr ing(adClipStrin g,,,,""),vbCr)

I thought perhaps it was returning a blank line because I ended my cursor,
in the csv file on a blank line at the end. I have this issue using FSO and
CSV files. I removed it but I still have the issue.

I am able to get past it by reducing my upperboundary by 1 but it feels like
a work-around.

for i = 0 to ubound(arrAccou nts) - 1
lprt arrAccounts(i)
next

Full source for this issue:
dim conn, rs, strPath, arrAccounts, arr, i
Set conn = Server.CreateOb ject("ADODB.Con nection")
Set rs = Server.CreateOb ject("ADODB.Rec ordset")
strPath = Server.Mappath( "/csv/")
conn.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & strPath & ";" &
"Extended Properties=Text "
rs.Open "SELECT DISTINCT caseNum FROM austin.csv", conn, adOpenStatic,
adLockOptimisti c, adCmdText
arrAccounts = split(rs.GetStr ing(adClipStrin g,,,,""),vbCr)
rs.Close
for i = 0 to ubound(arrAccou nts) - 1
lprt arrAccounts(i)
next

Am I causing the issue myself or is this a known issue?

TIA...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 22 '05 #1
2 10696
Roland,

I see this was posted almost a week ago with no replies.

It's not exactly the same method you're trying to use but here is what
has worked for me in reading a CSV file into a database's table.

You can connect to a csv file (which can be opened in Excel and which an
Excel file can be converted into) in good form just as you can to a
regular database.

The .csv file needs to be uploaded to the server.

And you can have two recordsets open at the same time.

So I'd suggest going through this recordset one row at a time and within
this loop add a new record to the "real" database's recordset.

And for help connecting to a text file using the Jet OLE DB provider:
http://www.carlprothman.net/Default....viderForTextFi
les

And based on the above link realize that the actual filename does NOT go
in the connection string - rather it goes in the SQL statement
(definitely a little tricky).

Best regards,
J. Paul Schmidt, Freelance ASP Web Designer
http://www.Bullschmidt.com
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...

<<
I have two(2) issues.

I'm experiencing a little difficulty and having to resort to a work
around.
I already found one bug, although stated the bug was only in ODBC, which
I'm
not using. It appears to be in the OLEDB driver also.

My connection was:
conn.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & strPath &
";" &
"Extended Properties='Tex t;HDR=NO;FMT=De limited'"

I got information from here:
http://msdn.microsoft.com/library/de.../en-us/dnclini
c/html/scripting030920 04.asp

I am using a schema.ini file and in it was:

[austin.csv]
Format=CSVDelim ited

Col1=personid Text
Col2=currDate Text
Col3=transCode Text
Col4=caseNum Text
Col5=caseType Text
Col6=defName Text
Col7=unknown Text

1. The first line in the csv file was being ignored, as if it was a
header
line. I verified by putting a blank line in the file and then I was able
to
see the first record, which was now the second line.

I read this was a bug but for FirstRowHasName s. It wasn't what I was
using
but the effect was the same for HDR=NO.
"However, due to a bug in the ODBC driver, specifying the
FirstRowHasName s
setting currently has no effect. In other words, the Excel ODBC driver
(MDAC
2.1 and later) always treats the first row in the specified data source
as
field names."

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

I found another article that fold me to use something else in the
schema.ini
file:
http://www.aspdb.com/Site/tor/Manual04/T_csvtext.shtm

ColNameHeader=F alse

My current schema.ini:
[austin.csv]
Format=CSVDelim ited
ColNameHeader=F alse

Col1=personid Text
Col2=currDate Text
Col3=transCode Text
Col4=caseNum Text
Col5=caseType Text
Col6=defName Text
Col7=unknown Text

I now get the first row without the need for the blank line.

My current connection string:
conn.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & strPath &
";" &
"Extended Properties=Text "
2. I am getting a blank line using rs.GetString but at the end.

My line:
arrAccounts = split(rs.GetStr ing(adClipStrin g,,,,""),vbCr)

I thought perhaps it was returning a blank line because I ended my
cursor,
in the csv file on a blank line at the end. I have this issue using FSO
and
CSV files. I removed it but I still have the issue.

I am able to get past it by reducing my upperboundary by 1 but it feels
like
a work-around.

for i = 0 to ubound(arrAccou nts) - 1
lprt arrAccounts(i)
next

Full source for this issue:
dim conn, rs, strPath, arrAccounts, arr, i
Set conn = Server.CreateOb ject("ADODB.Con nection")
Set rs = Server.CreateOb ject("ADODB.Rec ordset")
strPath = Server.Mappath( "/csv/")
conn.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & strPath &
";" &
"Extended Properties=Text "
rs.Open "SELECT DISTINCT caseNum FROM austin.csv", conn, adOpenStatic,
adLockOptimisti c, adCmdText
arrAccounts = split(rs.GetStr ing(adClipStrin g,,,,""),vbCr)
rs.Close
for i = 0 to ubound(arrAccou nts) - 1
lprt arrAccounts(i)
next

Am I causing the issue myself or is this a known issue?

TIA...

*** Sent via Developersdex http://www.developersdex.com ***
Jul 22 '05 #2
"Bullschmid t" <pa**@bullschmi dt.com-nospam> wrote in message
news:e3******** ******@tk2msftn gp13.phx.gbl...
: Roland,

Hi Paul...

: I see this was posted almost a week ago with no replies.

Yes, and I have an MSDN Universal subscription and I posted again with that
account and still nothing.

: It's not exactly the same method you're trying to use but here is what
: has worked for me in reading a CSV file into a database's table.
:
: You can connect to a csv file (which can be opened in Excel and which an
: Excel file can be converted into) in good form just as you can to a
: regular database.
:
: The .csv file needs to be uploaded to the server.

The file is already on the server.

: And you can have two recordsets open at the same time.

....but I only need one.

: So I'd suggest going through this recordset one row at a time and within
: this loop add a new record to the "real" database's recordset.

What "real" database? I have a .csv file.

: And for help connecting to a text file using the Jet OLE DB provider:
: http://www.carlprothman.net/Default....viderForTextFi
: les

Perhaps you missed this part of my post...

My connection was:
conn.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & strPath &
";" & "Extended Properties='Tex t;HDR=NO;FMT=De limited'"

: And based on the above link realize that the actual filename does NOT go
: in the connection string - rather it goes in the SQL statement
: (definitely a little tricky).

Yes, I know.

: rs.Open "SELECT DISTINCT caseNum FROM austin.csv", conn, adOpenStatic,
: adLockOptimisti c, adCmdText

Here is the full source again:

: Full source for this issue:
: dim conn, rs, strPath, arrAccounts, arr, i
: Set conn = Server.CreateOb ject("ADODB.Con nection")
: Set rs = Server.CreateOb ject("ADODB.Rec ordset")
: strPath = Server.Mappath( "/csv/")
: conn.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & strPath &
: ";" &
: "Extended Properties=Text "
: rs.Open "SELECT DISTINCT caseNum FROM austin.csv", conn, adOpenStatic,
: adLockOptimisti c, adCmdText
: arrAccounts = split(rs.GetStr ing(adClipStrin g,,,,""),vbCr)
: rs.Close
: for i = 0 to ubound(arrAccou nts) - 1
: lprt arrAccounts(i)
: next

My two issues are:

1. HDR in the connection string is dysfunctional. I can get past it with:

ColNameHeader=F alse

.... in the schema.ini file.

2. GetString returns an empty element at the end. I have had to employ a
workaround of decrementing the upper boundary of my array by one with loop.
GetString, to my knowledge, doesn't display this behavior when I retrieve
rows from a database. My CSV file does not have an empty line at the end.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1349
by: Mike | last post by:
Hi, I have a problem using ResourceManager GetString. The underlying resource is a simple text lookup using the resx data contents. When I specify a resource manager instance from an executable application, I am getting a proper execution of GetString. Conversely, and quite puzzling, the same attempt from a DLL with its own resx resource lookup data throws MissingManifestResourceException.
14
5849
by: Roland Hall | last post by:
I have two(2) issues. I'm experiencing a little difficulty and having to resort to a work around. I already found one bug, although stated the bug was only in ODBC, which I'm not using. It appears to be in the OLEDB driver also. My connection was: conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath & ";" & "Extended Properties='Text;HDR=NO;FMT=Delimited'"
3
2759
by: Roland Hall | last post by:
Three times the charm? Sorry for the repost. Trying to get my account right. I have two(2) issues. I'm experiencing a little difficulty and having to resort to a work around. I already found one bug, although stated the bug was only in ODBC, which I'm not using. It appears to be in the OLEDB driver also. My connection was:
1
2509
by: praveen79hebbar | last post by:
Hi, I have written a code to navigate through the recordset using MoveFirst,Movenext,MovePrevious and MoveLast i would like to fetch the records from the database and display it on a form in the textboxes.When i try to move from one record to another using MoveNext command it moves directly to the last record Here is the code Dim cn1 As ADODB.Connection Dim rs1 As ADODB.Recordset
6
2205
by: chopin | last post by:
I am working in Access 2003 in Windows XP. I am using Visual Basic for Applications, using DAO to write my modules. What I need to do is write a module that will compare each row to see if they are equal to each other or not. Basically, equal numbers in succession indicate a "music chord" which is why I need to do this. For example, if the table is like so: Notes.........Chord A.....................111 B.....................111...
3
1960
by: iheartvba | last post by:
Hi Guys, thanks for the great work you are doing I am working on a database in MS Access and am trying to bring up the last receipt number in the recordset (its the primary key of the recordset) but am running into this problem, every year the range of the receipts will be different e.g. 2005 it could be 80000 - 90000 while in 2006 it could be 10000 - 20000 meaning that the .MoveLast function would bring back the last receipt number...
0
1541
by: ShaggyMoose | last post by:
Yes, this is cross posted to microsoft.public.data.ado, but I figured there are two distinct parts to this with different audiences. I am trying to use ADODB to return a recordset from a DB2 stored procedure on AS400. All the procedure does is return a cursor for SELECT * FROM. I have tried both the "IBMDA400" and "Client Access ODBC" drivers. The first returns an empty recordset (incorrect), while the second returns the expected number...
9
35531
ADezii
by: ADezii | last post by:
One question which pops up frequently here at TheScripts is: 'How do I retrieve data from a Recordset once I've created it?' One very efficient, and not that often used approach, is the GetRows() Method of the Recordset Object. This Method varies slightly from DAO to ADO, so for purposes of this discussion, we'll be talking about DAO Recordsets. The ADO approach will be addressed in the following Tip. We'll be using a Query, consisting of 5...
3
43522
ADezii
by: ADezii | last post by:
Last Tip, we demonstrated the technique for retrieving data from a DAO Recordset, and placing it into a 2-dimensional Array using the GetRows() Method. This week, we will cover the same exact Method (GetRows()), but only as it applies to an ADO Recordset. Although there are similarities in the 2 methodologies, the ADO Method offers 2 more Optional Arguments, is a little more complex, and of course, the syntax is different in creating the...
0
8968
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8787
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9473
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.