Solved

adoquery Datatype decision based on 51% of the records...

Posted on 2004-08-16
4
315 Views
Last Modified: 2010-04-05
I really hope somebody can help me with the
following ;) :

I have a program reading the records from an excel file using the connection
like :

strConn:='Provider=Microsoft.Jet.OLEDB.4.0;' +
              'Data Source=' + Form1.ED_filename.Text + ';' +
              'Extended Properties="Excel 8.0;HDR=YES;MaxScanRows=0;MaxBufferSize=2048";';

and getting the fields type with:

var loopint:integer;
begin
  Adoquery1.Open;
  for loopint:=0 to adoquery1.FieldCount-1 do
  begin
    showmessage(adoquery1.FieldList[loopint].DataType);
  end;
end;

The Problem I have is that in a column called 'PurchaseOrder' I have 80% of the values that are numeric (like '0008332')
and 20% that are strings (like 'M002233')

When I use datatype, it returns FLOAT. I've tested it using the default 16 rows and inserting records like 9 strings and 7 values
(it returns STRING) and 9 values and 7 strings (it return FLOAT).

The problem is that if I have a field that has both Values and Text... it should return text, not values.

Thank you in advance!

Dave.
0
Comment
Question by:dcrudo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Assisted Solution

by:BaTy_GiRl
BaTy_GiRl earned 150 total points
ID: 11810184

>The problem is that if I have a field that has both Values and Text... it should return text, not values

Why you dont manipulate the rows which has strings, cutting the strings, maybe reviewing letter by letter...
use MidStr to cut the strings, and the function IsNumeric to review letter by letter    





0
 
LVL 1

Author Comment

by:dcrudo
ID: 11810403

Because the Program I'm trying to write should be able to automatically transfer Whole Excel worksheets data, not
always the same format, directly into a MySQL database.

I will not be using always the same format (the one above is just one example to replicate the issue).

If possible, I would like to avoid checking record by record... because some worksheets are quite big
(20 columns by 50K rows).



0
 
LVL 1

Accepted Solution

by:
aruana earned 150 total points
ID: 11842610
it may not be a good idea to use FieldList[].datatype to check for data in Excel.
What you are getting may be based on the first row only.
Also, what if a user enters numberic value in text format ? In excel, the appearance is the same as numeric value format.
i dont think you can avoid reading all of them.
50K rows for excel is certainly not a good idea for storing data.
is there any reason why you cant transfer all of them into MySQL as strings and later process them and change the data type if neccessary? this would be faster.
0
 
LVL 1

Author Comment

by:dcrudo
ID: 11879326
The answer to my problem:

Add 'IMEX=1' in the connection string will force JET to read all fields to return a Mixed field type and not
on the higher ration (51% number = number, 51% string = string)... if the field contain mixed number or
strings...it will always return string (mixed type).

Since no one of the answers helped me a lot... i will split the points for the effort!

Thank you!

Dave.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question