AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Datenbanken Delphi Update Database via SQL
Thema durchsuchen
Ansicht
Themen-Optionen

Update Database via SQL

Ein Thema von nanix · begonnen am 1. Dez 2009 · letzter Beitrag vom 6. Dez 2009
Antwort Antwort
Seite 1 von 3  1 23      
nanix
(Gast)

n/a Beiträge
 
#1

Update Database via SQL

  Alt 1. Dez 2009, 13:01
Datenbank: Absolute Database • Zugriff über: SQL
Hello friends,

My problem is that how to update database with SQL?

First for example i create items in DB but that just keeps adding them becouse the code is launched from timer.


Possible?
  Mit Zitat antworten Zitat
hoika

Registriert seit: 5. Jul 2006
Ort: Magdeburg
8.270 Beiträge
 
Delphi 10.4 Sydney
 
#2

Re: Update Database via SQL

  Alt 1. Dez 2009, 13:30
Hm ?

More info please.
Show us some code.

Update Table TabXXX Set Name='Hoika' Where Id=10


Heiko
Heiko
  Mit Zitat antworten Zitat
nanix
(Gast)

n/a Beiträge
 
#3

Re: Update Database via SQL

  Alt 1. Dez 2009, 13:47
Well this is concept code but it should do the trick...but how should it look for SQL?

Delphi-Quellcode:
if item then begin
           
           for i:=0 to 9 do begin
           ABSTable1.Open;
           ABSTable1.Insert; // adds new record into table

           ABSTable1.Fields.FieldByName('FirstName').AsString:='John';
           ABSTable1.Fields.FieldByName('LastName').AsString:='Heyho';
           ABSTable1.Fields.FieldByName('Sallary').AsString:='20.200';
           ABSTable1.Post; // saves newly created record to the table
           ABSTable1.Next;
           end;
           Item:=false;
end;
end
else begin
           for i:=0 to 9 do begin
          
           ABSTable1.Locate('ID',i,[]);
           ABSTable1.Edit; // starts updating of current record

           ABSTable1.Fields.FieldByName('FirstName').AsString:='John';
           ABSTable1.Fields.FieldByName('LastName').AsString:='Heyho';
           ABSTable1.Fields.FieldByName('Sallary').AsString:='20.200';
        
           ABSTable1.Post; // saves newly created record to the table
end;
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#4

Re: Update Database via SQL

  Alt 1. Dez 2009, 13:50
You shouldn't use TABSTable but TABSQuery
http://www.componentace.com/sql-query-delphi.htm
Markus Kinzler
  Mit Zitat antworten Zitat
nanix
(Gast)

n/a Beiträge
 
#5

Re: Update Database via SQL

  Alt 1. Dez 2009, 13:51
Exactly but how should this look in SQL with Query.I am not very familiar with SQL..
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#6

Re: Update Database via SQL

  Alt 1. Dez 2009, 13:59
insert into <Tablename> (FirstName, LastName, Sallary) values ( 'John', 'HeyHo', 20100); But you can also use paramters:
insert into <Tablename> (FirstName, LastName, Sallary) values ( :firstname, :lastname, :sallary );
Delphi-Quellcode:
ABSQuery1.ParamByName( 'firstname').Value := 'John';
...
Markus Kinzler
  Mit Zitat antworten Zitat
nanix
(Gast)

n/a Beiträge
 
#7

Re: Update Database via SQL

  Alt 1. Dez 2009, 14:06
Auu okay thank you.

Can i use update also with autoinc?
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#8

Re: Update Database via SQL

  Alt 1. Dez 2009, 14:07
This is an insert and in this case don't set the specific field
Markus Kinzler
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.541 Beiträge
 
Delphi 11 Alexandria
 
#9

Re: Update Database via SQL

  Alt 1. Dez 2009, 14:07
And updating an existing record looks like this:UPDATE <tablename> SET FirstName = 'John', LastName = 'HeyHo', Sallary = 20100 WHERE <conditions> Parameters can be used here as well.
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
nanix
(Gast)

n/a Beiträge
 
#10

Re: Update Database via SQL

  Alt 1. Dez 2009, 14:13
Thanks again what about if we say table has ID property for example

So that it updates based on EmployeeID Autoinc

EmployeeID Firstname
0 John
1 Lisa
2 Kimberly
3 Stephanie


Also could Autoinc start from 0? Like in the above example with Absolute Database.



Thanks
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 3  1 23      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:47 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz