Article View: borland.public.cppbuilder.database.ado
Article #3623Re: Cbuilder4 & Excell97
From: Shaun
Date: Sat, 20 Jul 2002 10:05
Date: Sat, 20 Jul 2002 10:05
37 lines
2077 bytes
2077 bytes
I'll post this answer in case anyone is interested, even if I have answered
the question myself.
This code uses a C++Builder4 form and fills a Listbox with data from a excel
spreadsheet using: Adodb, Microsoft Jet4.0.
(NO BDE Required)
Obviously you have already imported the respective activeX type libraries
and included them in the project.
TCOM_Connection cn = CoConnection::Create();
WideString S = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Build1.xls;Extended Properties=Excel 8.0;";
cn->ConnectionString = S;
cn->CursorLocation = Adodb_tlb::adUseClient;
cn->ConnectionTimeout = 100;
cn->Open(0,0,0,0);
WideString sql = "SELECT * from [TOTAL$]" ;
ListBox1->Items->Clear();
TCOM_Recordset rs = CoRecordset::Create();
rs->Open(sql.Detach(), (IDispatch *)cn, Adodb_tlb::adOpenDynamic,
Adodb_tlb::adLockOptimistic, 0);
do
{
Field* p = rs->Fields_->get_Item(TVariant("CITY"));
String s = p->get_Value();
ListBox1->Items->Add(s);
rs->MoveNext();
}while(rs->EOF == false);
rs->Close();
rs->Release();
cn->Close();
cn->Release();
regards Shaun
Technical Details
Message-ID:
<3d39315d_2@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-08!supernews.com!newsswitch.lcs.mit.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!nntp.infostrada.it!newsfeed01.sul.t-online.de!t-online.de!dnewsReferences:
<3d210c8e$1_2@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10698b,d7212406486d45a7 X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2002-07-20 03:15:23 PST From: "Shaun" <nospam@nospam.com> Newsgroups: borland.public.cppbuilder.database.ado References: <3d210c8e$1_2@dnews> Subject: Re: Cbuilder4 & Excell97 Date: Sat, 20 Jul 2002 22:05:20 +1200 Lines: 39 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 202.50.240.77 Message-ID: <3d39315d_2@dnews> X-Trace: dnews 1027158365 202.50.240.77 (20 Jul 2002 02:46:05 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-08!supernews.com!newsswitch.lcs.mit.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!nntp.infostrada.it!newsfeed01.sul.t-online.de!t-online.de!dnews