Board index » delphi » Access + SQL Problems

Access + SQL Problems

Hi!

I have a strange problem I will try to explain:

I have made an standard ODBC connection to an MS Access 97 Database stored
on my HD, which i use in my Delphi project.

To use the database within my project, i use one TTable refering to my
Master table in the MSADB called tblMaster, and one
TTable refering to my Detail table, called tblDetail.

To insert records to the tables on the fly I use an TUpdateSQL query.
For example, to insert som posts in the master table i use the following
code:

UpdateSQL.InsertSQL.Clear;
UpdateSQL.InsertSQL.Add ( 'INSERT INTO master ( file_id, name ) VALUES ( 1,
'Test' ); ');
UpdateSQL.ExecSQL( ukInsert );

This works really great!

But, now to the problem; When I like to delete records on the fly I use the
same type of code to perform the delete:

UpdateSQL.DeleteSQL.Clear;
UpdateSQL.DeleteSQL.Add( 'DELETE FROM master WHERE file_id = 1'; );
UpdateSQL.ExecSQL( ukDelete );

When i run my program, and performs the delete query, i recive an error
message: "Update Failed".

This is somhow strange, because when i monitored the SQL, I have seen that
the query has been both performed and executed without problems.
Also, when I check my records in the database afterwards, they are delete
(as I wished).
But why does I recieve an error message???

I have found a "workaround" of this problem, which looks like below:

UpdateSQL.DeleteSQL.Clear;
UpdateSQL.DeleteSQL.Add( 'DELETE FROM master WHERE file_id = 1'; );
try
    UpdateSQL.ExecSQL( ukDelete );
except
    // Do nothing with the raised exception
end;

But, this solution feels rather bad to implement in my program..

So my question is.. How can I perform DELETE querys without resulting in
Update errors??

Also, I wonder why I every time I open my TTable, gets an login dialog...??

Thanks in advance,

Mikael Stalvik
mikael.stal...@goteborg.utfors.se

 

Re:Access + SQL Problems


On Fri, 29 Oct 1999 13:48:54 +0200, "Mikael Stalvik"

Quote
<mikael.stal...@goteborg.utfors.se> wrote:
>I have made an standard ODBC connection to an MS Access 97 Database stored
>on my HD, which i use in my Delphi project.

>To use the database within my project, i use one TTable refering to my
>Master table in the MSADB called tblMaster, and one
>TTable refering to my Detail table, called tblDetail.

>To insert records to the tables on the fly I use an TUpdateSQL query.
>For example, to insert som posts in the master table i use the following
>code:

[...]

Quote
>This works really great!

>But, now to the problem; When I like to delete records on the fly I use the
>same type of code to perform the delete:

>UpdateSQL.DeleteSQL.Clear;
>UpdateSQL.DeleteSQL.Add( 'DELETE FROM master WHERE file_id = 1'; );
>UpdateSQL.ExecSQL( ukDelete );

>When i run my program, and performs the delete query, i recive an error
>message: "Update Failed".

You are having problems partly because you are misusing the TUpdateSQL
component. TUpdateSQL was designed as the update object for applying cached
updates to the base tables, not as the primary vehicle for issuing SQL
statements. For what you are doing, you really should be using a TQuery
component.

That "Updater failed" error is specific to the TUpdateSQL component. Use
the right tool for the job (TQuery), and you will be able to execute your
SQL statements without the error.

==========================================================================
Steve Koterski                  "Computers are useless. They can only give
Technical Publications          you answers."
Borland                                       -- Pablo Picasso (1881-1973)
http://www.borland.com/techpubs/delphi

Other Threads