🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #2962

Re: Importing data form diferent tables and database types

#2962
From: Vladimir Afanasyev
Date: Mon, 17 Feb 2003 08:26
88 lines
3700 bytes
Hi Ines,

"In�s Fern�ndez" <ifernandezmed@terra.es> wrote:
>Hi all!
>I am working in a program that must import data from a DBase table to
>another table in an SQL server database. The second table has two more
>fields than the first one, but the rest of the fields are the same.
>For example:
>If I have a record in the DBase table as follows:
>{10, 20, 15, 33, 6} (it has 5 integer fields with this values)
>I must save in the SQL server table something like this:
>{anything,anything, 10, 20, 15, 33, 6}
>
>Is there an easy way to do this?

For reading data from DBase table you can use BDE or ADO.
I didn't hear about component that did what you want.

Next sample save database data in the Excel (BDE for 
database and Automation for Excel):

//Table1 - database
// database converts to xls -> c:\\1.xls 
//FieldCanBeString - array that is indicates what 
//fields can be representing as string

Variant covFalse((short)false);
Variant vExcel;

//Excel's methods
Function WorkbooksP("Workbooks");
Function OpenF("Open");

//Variants for obtaining Dispatch interface
Variant WorkBooks;
Variant WorkBook;

PropertyGet WS("ActiveSheet");

Function SaveAsF("SaveAs");
Function CloseF("Close");
Function QuitF("Quit");
Function NewWorkBook("Add");
PropertyGet GetActiveSheet("ActiveSheet");
bool FieldCanBeString[10]={1,1,1,1,0,0,0,0,0,0};

//Creating Excel's object:
  vExcel=Variant::CreateObject("Excel.Application");
//do it visible (now you can see Excel on the screen 
//but really it is not obligatory):
  vExcel.Exec(PropertySet("Visible") << Variant((short)true));

  WorkBooks=vExcel.Exec(WorkbooksP);
  WorkBook=WorkBooks.Exec(NewWorkBook);
  Variant WorkSheet=WorkBook.Exec(GetActiveSheet);
//Excel ready for receiving data

//Open database:
Table1->Active=true;
int RC=Table1->RecordCount;

//Read data from DB and send it to Excel
Table1->First();
for(int i=1; i <= RC; ++i)
{
   for(int j=0; j < Table1->Fields->Count; ++j)
    {
        PropertySet Cells("Cells");
        if(!FieldCanBeString[j])continue;
        WorkSheet.Exec(Cells << i << j+1 << Table1->Fields->Fields[j]->AsString);
    }
Table1->Next();
}
Table1->Active=false;

//save file and close Excel
  WorkBook.Exec(SaveAsF << "c:\\1.xls");
  WorkBook.Exec(CloseF << covFalse);
  vExcel.Exec(QuitF);


For ADO you can use Borland's ADO component or you can 
use ADO directly. I never work with MSSQL server but 
for Sybase Adaptive Server Anywhere:
http://codecentral.borland.com/codecentral/ccweb.exe/listing?id=19557

Vladimir.
Technical Details
Message-ID: <3e509cbe$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!telocity-west!DIRECTV!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!lnewspeer01.lnd.ops.eu.uu.net!emea.uu.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3e4cf489$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 10698b,5718363b56ae1b18
X-Google-Attributes: gid10698b,public
X-Google-ArrivalTime: 2003-02-17 00:40:04 PST
From: "Vladimir Afanasyev" <avv@systema.kiev.ua>
Sender: "Vladimir Afanasyev" <avv@systema.kiev.ua>
Reply-To: "Vladimir Afanasyev" <avv@systema.kiev.ua>
Subject: Re: Importing data form diferent tables and database types
Newsgroups: borland.public.cppbuilder.database.ado
X-User-Info: 62.244.14.114 62.244.14.114    
X-Forwarded-For: 192.168.0.147
References:  <3e4cf489$1@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.65
Message-ID: <3e509cbe$1@newsgroups.borland.com>
Date: 17 Feb 2003 00:26:38 -0800
X-Trace: newsgroups.borland.com 1045470398 207.105.83.65 (17 Feb 2003 00:26:38 -0800)
Lines: 89
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!telocity-west!DIRECTV!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!lnewspeer01.lnd.ops.eu.uu.net!emea.uu.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail