Article View: borland.public.cppbuilder.database.ado
Article #2248Tricky ADO problem when deleting a DataSet object
From: Claudio Andre Heckler
Date: Mon, 15 Sep 2003 17:39
Date: Mon, 15 Sep 2003 17:39
66 lines
3157 bytes
3157 bytes
I'm building a small test app that queries an Access database using ADO; I
manually instantiate the Connection and DataSet objects, instead of having
them placed in a form.
The problem I'm having is that a weird exception is thrown when I'm deleting
the DataSet object.
The exception is: "Either BOF or EOF is True, or the current record has been
deleted. Requested operation requires a current record."
The minimal code I could come-up that shows this behaviour is next. If you
want to try it, please make sure you have an actual MDB file and change
file, table and column names to match those of your MDB.
Thanks in advance for any help!
Claudio A. Heckler
Note: code follows; the exception is triggered when the "delete oDataSet;"
line is executed;
Note2: this is a simple EXE app, with default compile switches;
// ======================= code starts here =======================
// Connection string:
AnsiString sConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
ExtractFilePath(Application->ExeName) + "Contas.mdb";
// create the connection object
TADOConnection *oConnection = new TADOConnection(NULL);
oConnection->LoginPrompt = false;
oConnection->Mode = cmReadWrite;
oConnection->ConnectionString = sConnStr;
oConnection->Connected = true;
// the SQL select statement:
AnsiString sSQL = "Select * From tbUsuario";
// create the DataSet object
TADODataSet *oDataSet = new TADODataSet(NULL);
oDataSet->Connection = oConnection;
oDataSet->CommandText = sSQL;
oDataSet->Open();
// do something ...
AnsiString sBuffer = "";
while (!oDataSet->Eof)
{
sBuffer = sBuffer + oDataSet->FieldByName("fdNome")->Value + "\r\n" ;
oDataSet->Next();
}
MessageDlg("Records read: \r\n" + sBuffer,
mtInformation, TMsgDlgButtons() << mbOK, 0);
// delete the dataset
delete oDataSet; // !!! this is where I get the error !!!
oDataSet = NULL;
// delete the connection:
oConnection->Connected = false;
delete oConnection;
oConnection = NULL;
// ======================= code ends here =======================
Technical Details
Message-ID:
<3f65f948@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!newsfeed.news2me.com!newsfeed.icl.net!newsfeed.fjserv.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10698b,c240d8d732995815,start X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2003-09-15 10:40:29 PST From: "Claudio Andre Heckler" <Claudio.Heckler@flexint.com> Newsgroups: borland.public.cppbuilder.database.ado Subject: Tricky ADO problem when deleting a DataSet object Date: Mon, 15 Sep 2003 14:39:21 -0300 Lines: 68 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 200.203.48.67 Message-ID: <3f65f948@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1063647560 200.203.48.67 (15 Sep 2003 10:39:20 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!newsfeed.news2me.com!newsfeed.icl.net!newsfeed.fjserv.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail