Article View: borland.public.cppbuilder.database.ado
Article #2270Re: Merging 2 Access Databases using ADO fails - HELP
From: Viatcheslav V. Vassiliev
Date: Tue, 23 Sep 2003 10:49
Date: Tue, 23 Sep 2003 10:49
172 lines
7278 bytes
7278 bytes
>ADOConnection1->ConnectOptions = coAsyncConnect;
Remove this line. If connection is really asynchrounous you should wait when
connection will be establised.
> ADOConnection1->ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;";
> ADOConnection1->ConnectionString = ADOConnection1->ConnectionString +
> "Data Source=";
> ADOConnection1->ConnectionString = ADOConnection1->ConnectionString +
> "00B0D0F6FF9D.MDB";
> ADOConnection1->ConnectionString = ADOConnection1->ConnectionString +
> ";Persist Security Info=False";
Do not do like this. Assigning connection string value does not only concat
internal string but also some other processing. Set connection string at
once - if you need construct internal AnsiString or WideString variable and
assign it to ConnectionString property.
> ADODataSet1->LockType = ltReadOnly ;
> ADODataSet2->LockType = ltBatchOptimistic;
You do not need batch updates.
>Other code.
You do many useless things. The best way is to execute SQL query like:
DELETE * FROM [TableName] WHERE ID='...'
for every table you need. You may use ADOConnection1->Execute() for this.
Note brackets around table name - they are required in case table name is
one of keywords. ID='...' should be constructed as UID = ... + "ID=" +
QuotedStr(ID), this is required if you have quote char inside ID value, you
may use AnsiQuotedStr.
> if (ADODataSet1->RecordCount > 0)
> ADODataSet2->Clone(ADODataSet1);
This will not copy data, it will clone cursor and will not change data in
database, use SQL query like:
Insert * into [DstTable] from [SrcTable] in "C:\\Temp\\SrcDB.mdb"
Table structrure must be equal for DstTable and SrcTable. You may need
execute "Delete * from [DstTable]" if you need to empty DstTable first.
//----------------------
Regards,
Viatcheslav V. Vassiliev
http://www.oledbdirect.com
The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)
"Louie Athanasiadis" <la@uow.edu.au> �������/�������� � �������� ���������:
news:3f6fc7b9@newsgroups.borland.com...
> Hello all
> I am writing a program that accepts Access database files from machines in
> my faculty and stores the files under the machines MAC address (this
works)
> A thread then tries to merge each incoming Access database with the main
> Access database. It tries to delete the old data stored in each table in
the
> main database and then merge in the data provided by the Access database
> (that was upload) into the main table. I have tried various ways of doing
> this, but get various error conditions and the program fails, it has to do
> with write permissions (or what ever with the main database) . The line
with
> /****/ mark below fails with an exception
> "Current Recordset does not support updating. This may be a limitation of
> the provider, or of the selected locktype"
>
> I have tried everything I know ( new to ADO programming - new to any
> Database programing on C++ Builder). Any help welcomed. My merge code is
> below
>
>
>
>
>
>
> void __fastcall TForm1::testButtonClick(TObject *Sender)
> {
> TStrings *TableList = new TStringList;
> TStrings *FieldList = new TStringList;
> AnsiString str1;
> AnsiString str2;
> AnsiString str3;
> AnsiString ID;
> AnsiString UID;
> AnsiString ColumnName;
> int i;
> int j;
>
> ADOConnection1->ConnectOptions = coAsyncConnect;
> ADOConnection1->Close();
> ADOConnection1->ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;";
> ADOConnection1->ConnectionString = ADOConnection1->ConnectionString +
> "Data Source=";
> ADOConnection1->ConnectionString = ADOConnection1->ConnectionString +
> "00B0D0F6FF9D.MDB";
> ADOConnection1->ConnectionString = ADOConnection1->ConnectionString +
> ";Persist Security Info=False";
> ADOConnection1->Connected = true;
> ADOConnection1->Open();
>
> ADOConnection2->ConnectOptions = coAsyncConnect;
> ADOConnection2->Close();
> ADOConnection2->Mode = cmReadWrite;
> ADOConnection2->ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;";
> ADOConnection2->ConnectionString = ADOConnection2->ConnectionString +
"D
> ata Source=";
> ADOConnection2->ConnectionString = ADOConnection2->ConnectionString +
> "SOSOS.MDB";
> ADOConnection2->ConnectionString = ADOConnection2->ConnectionString +
> ";Persist Security Info=False";
> ADOConnection2->Connected = true;
> ADOConnection2->Open();
>
> ADOConnection2->GetTableNames(TableList, false);
> ADODataSet1->LockType = ltReadOnly ;
> ADODataSet2->LockType = ltBatchOptimistic;
> ADOCommand1->CommandText = "Select * from SOS";
> ADODataSet1->Recordset = ADOCommand1->Execute();
>
> str1 = ADODataSet1->Fields->Fields[0]->AsString;
> str2 = ADODataSet1->Fields->Fields[1]->AsString;
> str3 = ADODataSet1->Fields->Fields[4]->AsString;
> ID = str1;
> UID = str2 + "\\" + str3;
>
> for ( i = 0; i < TableList->Count; i++)
> {
> if (TableList->Strings[i] == "Users" )
> ADOCommand1->CommandText = "Select * from Users where
UserID='"
> + UID + "'";
> else
> ADOCommand1->CommandText = "Select * from " +
> TableList->Strings[i];
> ADODataSet1->Recordset = ADOCommand1->Execute();
> ADODataSet1->GetFieldNames(FieldList);
>
> if (TableList->Strings[i] == "Users")
> ADOCommand2->CommandText = "Select * from Users where
UserID='"
> + UID + "'" ;
> else
> ADOCommand2->CommandText = "Select * from " +
> TableList->Strings[i]+ " where " + FieldList->Strings[0] + "='" + ID +
"'";
>
>
> ADODataSet2->Recordset = ADOCommand2->Execute();
>
>
> if (TableList->Strings[i] != "Users" )
> ADODataSet2->DeleteRecords(arAll);
> /**********************************/
>
> if (ADODataSet1->RecordCount > 0)
> ADODataSet2->Clone(ADODataSet1);
> ADODataSet2->Post();
>
> // ADODataSet2->UpdateBatch(arAll);
>
> }
> ADOConnection1->Close();
> ADOConnection2->Close();
>
> }
>
>
Technical Details
Message-ID:
<3f70323b@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3f6fc7b9@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 10698b,afa7b3c61744962f X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2003-09-23 04:50:58 PST From: "Viatcheslav V. Vassiliev" <support@oledbdirect.com> Newsgroups: borland.public.cppbuilder.database.ado References: <3f6fc7b9@newsgroups.borland.com> Subject: Re: Merging 2 Access Databases using ADO fails - HELP Date: Tue, 23 Sep 2003 14:49:28 +0400 Lines: 174 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 213.234.218.42 Message-ID: <3f70323b@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1064317499 213.234.218.42 (23 Sep 2003 04:44:59 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail