Article View: borland.public.cppbuilder.database.ado
Article #2269Merging 2 Access Databases using ADO fails - HELP
From: Louie Athanasiadis
Date: Tue, 23 Sep 2003 04:08
Date: Tue, 23 Sep 2003 04:08
109 lines
4770 bytes
4770 bytes
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:
<3f6fc7b9@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10698b,afa7b3c61744962f,start X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2003-09-22 21:13:34 PST From: "Louie Athanasiadis" <la@uow.edu.au> Newsgroups: borland.public.cppbuilder.database.ado Subject: Merging 2 Access Databases using ADO fails - HELP Date: Tue, 23 Sep 2003 14:08:31 +1000 Lines: 111 X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 130.130.112.238 Message-ID: <3f6fc7b9@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1064290233 130.130.112.238 (22 Sep 2003 21:10:33 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail