Solved

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

Posted on 2006-07-15
4
338 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

695 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