Solved

CREATE TQUERY AND TUPDATESQL IN RUN TIME AND INSERTING ROW IN MY DATABASE

Posted on 2006-07-15
4
328 Views
Last Modified: 2010-04-05
I WOULD LIKE TO CREATE ONE OBJECT TQUERY AND ONE TUPDATESQL TO INSERT ONE ROW IN MY DATABASE.

HERE IS THE CODE THAT I USE FOR DO THAT, BUT LIKE I SAD I WANT CREATE THIS OBJECTS (TQUERY AND TUPDATESQL) IN RUNTIME:
SQLERRO IS TUPDATESQL AND QUERY_ERRO IS TQUERY

   SQLErro.InsertSQL.Clear;
   SQLErro.InsertSQL.Add('insert into TB_ERRO');
   SQLErro.InsertSQL.Add('(DATA, MENSAGEM, FORMNAME, FORMCAPTION, OBJETOATIVO)');
   SQLErro.InsertSQL.Add(' values');
   SQLErro.InsertSQL.Add('(''' + DateTimeToStr(now()) + ''',');
   SQLErro.InsertSQL.Add('''' + E.Message + ''',');
   SQLErro.InsertSQL.Add('''' + screen.ActiveForm.Name + ''',');
   SQLErro.InsertSQL.Add('''' + Screen.ActiveForm.Caption + ''',');
   SQLErro.InsertSQL.Add('''' + screen.ActiveControl.Name + ''')');
   Query_Erro.Insert;
   Query_Erro.ApplyUpdates;
   SQLErro.InsertSQL.Clear;
0
Comment
Question by:rafaelrgl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 500 total points
ID: 17115834
the simple way to do this is to select the query on the form
then do a ctrl-c (copy)
next, find a nice spot in your unit and paste

you should get something like

object Query1: TQuery
  DatabaseName = 'DBDEMOS'
  SQL.Strings = (
    'select * from biolife')
  Left = 424
  Top = 296
end

object UpdateSQL1: TUpdateSQL
  Left = 432
  Top = 304
end

now simply replace the bits you need with delkphi code
e.g.
Query_Erro :=  TQuery.create(nil);
Query_Erro.DatabaseName := 'DBDEMOS';
Query_Erro.SQL.Text := 'select * from biolife';

SQLErro := TUpdateSQL.create(nil);

0
 
LVL 1

Author Comment

by:rafaelrgl
ID: 17116001
[Error] FrmPrinc.pas(445): Undeclared identifier: 'Query_Erro'
[Error] FrmPrinc.pas(445): Undeclared identifier: 'TQuery'
[Error] FrmPrinc.pas(446): Undeclared identifier: 'SQLErro'
[Error] FrmPrinc.pas(446): Undeclared identifier: 'TUpdateSQL'
[Error] FrmPrinc.pas(446): Missing operator or semicolon
[Error] FrmPrinc.pas(447): Missing operator or semicolon
[Hint] FrmPrinc.pas(233): Private symbol 'UniqueUser' declared but never used
[Fatal Error] Nucleo_Server.dpr(31): Could not compile used unit 'FrmPrinc.pas'
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17116871
Sorry, i thought you knew that bit.
If you wish to create it dynamically you will need to make a variable for it somewhere

eg. if you wish to create it for your form you'd have

private // at the top of your unit you will seee this section
    Query_erro: TQuery;
    SQLErro: TUpdateSQL;
end;

but if you wish to create it in an object, eg. for yout TIdTCPServer, then you'd put it in the data object you create for that
eg.
type
    TClientSpecificData = class(TObject)
  private
    Query_erro: TQuery;
    SQLErro: TUpdateSQL;
...
etc...
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17116889
you will also need to add DB, and DBTables to your USES clause at the top of your unit
eg.
uses windows..(etc)...,DBTables, DB;
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question