Devart Forum Index

The time now is Thu 09 Sep 2010 03:59

TUniTable ACCESS update error

 
Post new topic   Reply to topic    Devart Forum Index -> Universal Data Access Components
View previous topic :: View next topic  
Author Message
RichTat



Joined: 04 Mar 2008
Posts: 4
Location: UK

PostPosted: Wed 28 Jul 2010 12:00    Post subject: TUniTable ACCESS update error Reply with quote

C++ Builder 2010 with Microsoft Access ODBC driver ACEODBC.DLL and AccessUniProvider1 and TUniTable : the following code gives an error:
'raised exception EDatabaseError with message'Update failed found 0 records' at the last Post() line.
The table is empty with the field "ID" as the primary key and type NUMBER not AUTONUMBER.
The record is actually added to the table.
Where am I going wrong - all this type of code worked with the TADOTable components.

void __fastcall TForm1::Button3Click(TObject *Sender)
{
int n;

tabTest->Insert();
tabTest->FieldByName("ID")->AsInteger = 1;
tabTest->Post();
tabTest->First();
n = tabTest->RecordCount;
if (n == 1)
{
tabTest->Edit();
tabTest->FieldByName("CID")->AsInteger = 1;
tabTest->Post();
}
}
_________________
Richard Tatlow
Back to top
View user's profile Send private message Visit poster's website
bork
Devart Team


Joined: 12 Mar 2010
Posts: 467

PostPosted: Wed 28 Jul 2010 12:25    Post subject: Reply with quote

Hello

Please provide us the DDL script for creating the tables that are used in your sample.
Back to top
View user's profile Send private message
RichTat



Joined: 04 Mar 2008
Posts: 4
Location: UK

PostPosted: Wed 28 Jul 2010 12:39    Post subject: Reply with quote

Hello bork

I use Microsoft Access 2003 to create the tables and to manipulate them eg deleting records for repeated testing, adding new fields and deleting unwanted fields etc. during development.

Should I use a script instead and try again ?
_________________
Richard Tatlow
Back to top
View user's profile Send private message Visit poster's website
bork
Devart Team


Joined: 12 Mar 2010
Posts: 467

PostPosted: Wed 28 Jul 2010 14:40    Post subject: Reply with quote

The LockMode property is set to lmOptimistic by default and before editing TUniTable try to lock the record. Your field CID has default value 0 and TuniTable.Options.DefaultValues is False. So the default value was inserted into the database, but TUniTable doesn't know about it. As a result TUniTable cannot create the WHERE clause correctly. I can offer the following ways to resolve this issue:
- You can set the LockMode property to lmNone
- You can change the default value of the CID field to Null in the MS Access database
- You can set Options.UpdateAllFields to True
- You can set RefreshOption.roBeforeEdit to True
You can use any of these ways to resolve the issue.
Back to top
View user's profile Send private message
RichTat



Joined: 04 Mar 2008
Posts: 4
Location: UK

PostPosted: Wed 28 Jul 2010 16:25    Post subject: Reply with quote

Hello bork

Yes - thank you - the RefreshOption.roBeforeEdit to True seemed to be the logical one to use and that worked.
I have other problems with ODBC syntax errors which I tracked down to illegal field names (Date, etc. - do I ever learn !)
The ODBC trace mechanism is not very helpful in determining the exact causes of problems.
Is there a way of monitoring in the client program the SQL statements submitted by the UniDAC component to the database servers and/or ODBC channel ? This would give an quick and easy method of analysing errors.
_________________
Richard Tatlow
Back to top
View user's profile Send private message Visit poster's website
bork
Devart Team


Joined: 12 Mar 2010
Posts: 467

PostPosted: Mon 02 Aug 2010 11:13    Post subject: Reply with quote

Hello

You can use TUniSQLMonitor to get the list of SQL queries that were sent to a database. You should add the OnSQL event handler:
Code:
procedure TForm1.UniSQLMonitor1SQL(Sender: TObject; Text: String;
  Flag: TDATraceFlag);
begin
  Memo1.Lines.Add(Text);
  Memo1.Lines.Add('---');
end;

You should quote field names like "Date" in the queries and set the Optopns.QuoteNames option to True to generate correct update queries.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Devart Forum Index -> Universal Data Access Components All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum