Error reading records with double quotes through data control in VB6

Error reading records with double quotes through data control in VB6

Post by Robert Alber » Fri, 14 Jan 2000 04:00:00



My VB6 project has a data control with
Data1.Connect = Text;
Data1.RecordSource = MyFile#txt
Data1.Options = 0
Data1.RecordsetType = 0

MyFile.txt is a comma delimited file with two fields.
Sample records:
qweqwe,rtyrty
asdasd,fghfgh
zxczxc,"vbnvbn" <-- Note that some records can have a quote
fghfgh,jkljkl
xcvxcv,bnmbnm

If the quotes are stripped from the file before
running this code, there is no error.

We don't want to have to tell our customers that they
have to search and replace the double quotes in their
file before they use our software.

For simplicity's sake, here's an abbreviated code
snippet that illustrates how and where the error
is being generated:

On Error GoTo 0
    Do While Not Data1.Recordset.EOF
        Debug.Print Data1.Recordset(0)
        Debug.Print Data1.Recordset(1)
        Data1.Recordset.MoveNext
    Loop

Run-time error '-2147417848(80010108)':
Automation error
The object invoked has disconnected from its clients.

I click on debug and the code appears with
the break highlighted at the line that says
Debug.Print Data1.Recordset(0).

I click the run button and another error immediately
appears:
Run-time error '3015':
" isn't an index to this table. Look in the indexes
collection of the TableDef to determine the valid
index names.

I click on debug and the code appears with
the break highlighted at the same line as before.

I then change the line
On Error GoTo 0
to
On Error Resume Next.

Then there is no break on the error, but the execution
stops as if the record with the double quotes is the
last record in the file. If it continued to read
records after the problem record I'd simply use
On Error Resume Next, but I can't do that because
all of the records in the file have to be read.

My question is, is there a way to do this so that
double quotes are ignored and all of the records
are read? Is there some property of the data control
that needs to be set differently?

Thanks in advance.

 
 
 

Error reading records with double quotes through data control in VB6

Post by Jim in Clevelan » Fri, 14 Jan 2000 04:00:00



> My VB6 project has a data control with
> Data1.Connect = Text;
> Data1.RecordSource = MyFile#txt
> Data1.Options = 0
> Data1.RecordsetType = 0

> MyFile.txt is a comma delimited file with two fields.
> Sample records:
> qweqwe,rtyrty
> asdasd,fghfgh
> zxczxc,"vbnvbn" <-- Note that some records can have a quote
> fghfgh,jkljkl
> xcvxcv,bnmbnm

> If the quotes are stripped from the file before
> running this code, there is no error.

> We don't want to have to tell our customers that they
> have to search and replace the double quotes in their
> file before they use our software.

<snip>

  Don't know of any "ignore quotes" switch you can toggle in a Data
Control ;-)
  So the presence of the quote symbol serves no purpose in your
processing of the data?  Then it seems to me you solve your clients'
problem by adding a step to your program to process the file and strip
out the quotation marks before you make the records available to your
Data Control.  This will cost some processing time, but probably not
noticeable unless you're talking hundreds of records in the .txt file or
a way old PC.
  Another option would be investigate how the quotes get into .txt file
in first place and find a way to prevent it.
--
Jim in Cleveland
If you're writing to me, in my address
change "REAL_Address.see.below" to "worldnet.att.net"

"What's so funny 'bout peace, love & understanding?"
     - Nick Lowe

 
 
 

1. saving data with single quote or double quote

i have a html page which request data, then it will construct a string
which call a stored procedure to insert data to a SQL database.

the statement is like this:
exec sp_xyz 'param1', 'param2', ...

param1 and param2 may contain single quote or double quote

how can i save the data containing single quote and/or double quote?

thanks

Sent via Deja.com
http://www.deja.com/

2. recordset to database conversion

3. VB6 Data Control + Microsoft Access (French) = Error 525 (Data Access Error)

4. Can't create 8i database

5. Single-quote and double-quote characters in fields

6. Closed recordset with stored procedure

7. REPLACE one quote to double quotes

8. Artifical Intelligence

9. quotes, double quotes: how to treat them?

10. Question about quote and double quote characters

11. help: double quote vs. single quote string delimiter

12. ODBC /w Schema.ini and Delimited Records(:)...Problem With Double Quote

13. rules of single quotes and double quotes