Re: Connecting to Excel



"Spencer Jago" <greenarmylee@xxxxxxxxxxxxx> wrote in
news:44e6cfcf@xxxxxxxxxxxxxxxxxxxxxx:

Hello there

I am writing a program which will display data from an excel
spread*** in a DBGrid. The problem I am having is that at run time I
am getting an exception which says that it 'Could not find an
installable ISAM'.

Any ideas?

I'm suspecting it's something to do with the connection string. It
looks like this:

strConn:='Provider=Microsoft.Jet.OLEDB.4.0;' + 'Data Source=' +
'C:\Fantasy 2007.xls;' + 'Extended Property=Excel 8.0;';

AdoConnection1.Connected:=False;
AdoConnection1.ConnectionString:=strConn;

I think you need double quotes, thus:

strConn:='Provider="Microsoft.Jet.OLEDB.4.0";' + 'Data Source=' +
'"C:\Fantasy 2007.xls;"' + 'Extended Property="Excel 8.0;"';

The single quotes are for Delphi, the double quotes are for ADO.

I would code using Format:

var
Prov, DSrc, XPro: String;

Prov := 'Microsoft.Jet.OLEDB.4.0';
DSrc := 'C:\Fantasy 2007.xls';
XPro := 'Excel 8.0';

strConn := Format('Provider="%s";Data Source="%s";Extended Property="%s";';
[Prov, DSrc, XPro]);

HTH

--
For e-mail address, remove the XXs
.


Quantcast