| View previous topic :: View next topic |
| Author |
Message |
shraga milon Guest
|
Posted: Tue May 08, 2007 10:32 pm Post subject: Null values when reading excel with Ado :-( |
|
|
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
|
Posted: Wed May 09, 2007 8:07 am Post subject: Re: Null values when reading excel with Ado :-( |
|
|
Can you show your code?
- Clayton |
|
| Back to top |
|
 |
shraga milon Guest
|
Posted: Wed May 09, 2007 8:11 am Post subject: Re: Null values when reading excel with Ado :-( |
|
|
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
|
Posted: Wed May 09, 2007 3:02 pm Post subject: Re: Null values when reading excel with Ado :-( |
|
|
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
|
Posted: Wed May 09, 2007 5:22 pm Post subject: Re: Null values when reading excel with Ado :-( |
|
|
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 |
|
 |
|