BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Null values when reading excel with Ado :-(

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO)
View previous topic :: View next topic  
Author Message
shraga milon
Guest





PostPosted: Tue May 08, 2007 10:32 pm    Post subject: Null values when reading excel with Ado :-( Reply with quote



Hi
I have and excel file with this values:

kod
227
228
223
313


When i read this table with TAdoDataset (SELECT * from ....) and i check the
values of field kod, i get null value in the "223" value.

if i save the xls file to csv or txt the value is ok , buf if i read it
with ado, i get null in this row :-(

Any help ?

Shraga
Back to top
Clayton Arends
Guest





PostPosted: Wed May 09, 2007 8:07 am    Post subject: Re: Null values when reading excel with Ado :-( Reply with quote



Quote:
Any help ?

Can you show your code?

- Clayton
Back to top
shraga milon
Guest





PostPosted: Wed May 09, 2007 8:11 am    Post subject: Re: Null values when reading excel with Ado :-( Reply with quote



Hi
This is the procedure that init the ado to excel file:

Procedure TDM_Excel.Init_Excel(pExcel_FileName:String);
var
strConn:widestring;
Sheets:TStringList;
begin
strConn:='Provider=Microsoft.Jet.OLEDB.4.0;' +
'Data Source=' + pExcel_FileName + ';' +
'Extended Properties=Excel 8.0;';

Excel_ADOConnection.Connected:=False;
Excel_ADOConnection.ConnectionString:=strConn;
Sheets:=TStringList.Create;
try
Excel_ADOConnection.Open;
Excel_ADOConnection.GetTableNames(Sheets,True);
if Sheets.Count-1>=0 then begin
Excel_ADODataSet.Close;
Excel_ADODataSet.CommandText:='SELECT * FROM ['+Sheets[0]+']';
Excel_ADODataSet.Open;
end
else begin
ErrorMessage('no sheets in the excel !!!');
end;
Sheets.Free;
except
on e:Exception do begin
ErrorMessage(problem with loading excel:' +CR+ pExcel_FileName);
Sheets.Free;
Abort;
end;
end;
End;

And here is the code on the table:

try
Mone:=0;
Screen.Cursor:=crHourGlass;
Ok:=True;
While not DM_Excel.Excel_ADODataSet.Eof and ok do begin
Inc(Mone);
if DM_Excel.Excel_ADODataSet.Fields[0].IsNull then // *
here is the null checking to know if there are more rows with data in the
excel
break
else
Asc2Dbf;
DM_Excel.Excel_ADODataSet.Next;
End;
Result:=True;
Finally
DM_Excel.Excel_ADODataSet.Close;
DM_Excel.Excel_ADOConnection.Connected:=False;
Screen.Cursor:=crDefault;
End;
end




"Clayton Arends" <nospam_claytonarends (AT) hotmail (DOT) com> wrote in message
news:46413aed$1 (AT) newsgroups (DOT) borland.com...
Quote:
Any help ?

Can you show your code?

- Clayton
Back to top
shraga milon
Guest





PostPosted: Wed May 09, 2007 3:02 pm    Post subject: Re: Null values when reading excel with Ado :-( Reply with quote

here is the link to the demo file.

http://www.filesend.net/download.php?f=411509d74ad7b6d3b7bcc76861de6a76
Shraga

"shraga milon" <shragami (AT) zahav (DOT) net.il> wrote in message
news:46415d8d (AT) newsgroups (DOT) borland.com...
Quote:
Hi
This is the procedure that init the ado to excel file:

Procedure TDM_Excel.Init_Excel(pExcel_FileName:String);
var
strConn:widestring;
Sheets:TStringList;
begin
strConn:='Provider=Microsoft.Jet.OLEDB.4.0;' +
'Data Source=' + pExcel_FileName + ';' +
'Extended Properties=Excel 8.0;';

Excel_ADOConnection.Connected:=False;
Excel_ADOConnection.ConnectionString:=strConn;
Sheets:=TStringList.Create;
try
Excel_ADOConnection.Open;
Excel_ADOConnection.GetTableNames(Sheets,True);
if Sheets.Count-1>=0 then begin
Excel_ADODataSet.Close;
Excel_ADODataSet.CommandText:='SELECT * FROM ['+Sheets[0]+']';
Excel_ADODataSet.Open;
end
else begin
ErrorMessage('no sheets in the excel !!!');
end;
Sheets.Free;
except
on e:Exception do begin
ErrorMessage(problem with loading excel:' +CR+ pExcel_FileName);
Sheets.Free;
Abort;
end;
end;
End;

And here is the code on the table:

try
Mone:=0;
Screen.Cursor:=crHourGlass;
Ok:=True;
While not DM_Excel.Excel_ADODataSet.Eof and ok do begin
Inc(Mone);
if DM_Excel.Excel_ADODataSet.Fields[0].IsNull then // *
here is the null checking to know if there are more rows with data in the
excel
break
else
Asc2Dbf;
DM_Excel.Excel_ADODataSet.Next;
End;
Result:=True;
Finally
DM_Excel.Excel_ADODataSet.Close;
DM_Excel.Excel_ADOConnection.Connected:=False;
Screen.Cursor:=crDefault;
End;
end




"Clayton Arends" <nospam_claytonarends (AT) hotmail (DOT) com> wrote in message
news:46413aed$1 (AT) newsgroups (DOT) borland.com...
Any help ?

Can you show your code?

- Clayton


Back to top
shraga milon
Guest





PostPosted: Wed May 09, 2007 5:22 pm    Post subject: Re: Null values when reading excel with Ado :-( Reply with quote

The problem was solved:-)
You must put IMEX=1 in the connection string :
'Extended Properties="Excel 8.0;IMEX=1"'

"Clayton Arends" <nospam_claytonarends (AT) hotmail (DOT) com> wrote in message
news:46413aed$1 (AT) newsgroups (DOT) borland.com...
Quote:
Any help ?

Can you show your code?

- Clayton
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.