Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
Databases
»
Run SqlQuery1 using button
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
IRC channel
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
IDE instability on Raspbe...
by
rvk
[
Today
at 10:37:14 am]
Boleeman's projects are p...
by
AlexTP
[
Today
at 10:18:04 am]
Using KeyPress event, how...
by
alpine
[
Today
at 10:02:15 am]
Understanding and adjusti...
by
circular
[
Today
at 09:55:30 am]
Your best UI design - con...
by
circular
[
Today
at 09:36:11 am]
ZeosDBO and querys using ...
by
Zvoni
[
Today
at 09:27:17 am]
STARS with line border st...
by
Boleeman
[
Today
at 09:13:29 am]
JEDI error but unit compi...
by
DomingoGP
[
Today
at 08:28:17 am]
Configure JCF messages
by
DomingoGP
[
Today
at 08:19:10 am]
Any upgrades to fpWeb pag...
by
AlexTP
[
Today
at 08:10:55 am]
Zeos components. Had to c...
by
dbannon
[
Today
at 07:26:11 am]
A button require administ...
by
Fibonacci
[
Today
at 05:57:21 am]
How to detect one externa...
by
d2010
[
Today
at 12:24:32 am]
Center Lost Window featur...
by
Tony Stone
[
Today
at 12:06:16 am]
Complex package installat...
by
wp
[March 27, 2024, 10:47:45 pm]
Controlling the behavior ...
by
wp
[March 27, 2024, 10:43:40 pm]
A "leisure" question on W...
by
EventHorizon
[March 27, 2024, 10:18:38 pm]
need advice about the fol...
by
jamie
[March 27, 2024, 09:56:39 pm]
[SOLVED] Completion box s...
by
Martin_fr
[March 27, 2024, 08:44:09 pm]
Dialog ShowModal and an i...
by
d7_2_laz
[March 27, 2024, 08:25:18 pm]
Offical launch of the 1 B...
by
Gustavo 'Gus' Carreno
[March 27, 2024, 07:41:48 pm]
Problem setting length of...
by
Remy Lebeau
[March 27, 2024, 05:41:10 pm]
TDBLookupcombobox seems u...
by
Fantablup
[March 27, 2024, 05:18:04 pm]
Poll: Watches and Display...
by
Martin_fr
[March 27, 2024, 03:58:57 pm]
Help needed with Cairo / ...
by
AL
[March 27, 2024, 02:35:10 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Run SqlQuery1 using button (Read 3216 times)
Bui Thiet
Newbie
Posts: 6
Run SqlQuery1 using button
«
on:
January 31, 2020, 04:21:20 pm »
How to Run SqlQuery1 using button
Logged
JanRoza
Hero Member
Posts: 672
Re: Run SqlQuery1 using button
«
Reply #1 on:
January 31, 2020, 05:30:33 pm »
Depends on what you want to do when the button is clicked.
If you want to make another selection from a table code could look like this:
Code: Pascal
[Select]
[+]
[-]
procedure
button1
.
click
var
strSQL
:
String
;
begin
strSQL
:
=
'SELECT * FROM <table-name>'
;
SQLQuery1
.
Active
:
=
false
;
SQLQuery1
.
SQL
.
Text
:
=
strSQL
;
SQLQuery1
.
Active
:
=
true
;
end
;
Replace <table-name> by the real name of the table you want to use.
Logged
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
Lazarus 3.2 FPC 3.2.2
CodeTyphon 8.40 FPC 3.3.1
Bui Thiet
Newbie
Posts: 6
Re: Run SqlQuery1 using button
«
Reply #2 on:
February 01, 2020, 04:12:58 pm »
Thanks JanRoza and it worked fine, it was great
Logged
Bui Thiet
Newbie
Posts: 6
Re: Run SqlQuery1 using button
«
Reply #3 on:
February 01, 2020, 04:59:53 pm »
How to compare values in Edit1 with values with Date Columns of type Date in Database. I want to sum by condition.
Sincerely thank you, hope you will help me.
Logged
JanRoza
Hero Member
Posts: 672
Re: Run SqlQuery1 using button
«
Reply #4 on:
February 02, 2020, 12:44:26 am »
How about:
Code: Pascal
[Select]
[+]
[-]
// Check edit1 against a database date
if
StrToDate
(
edit1
.
Text
)
<
=
SQLQuery1
.
FieldByName
(
'<Date fieldname>'
)
.
asString
then
…
.......;
Search this forum for more info on working with databases, especially wiki pages. You can learn a lot from them.
Logged
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
Lazarus 3.2 FPC 3.2.2
CodeTyphon 8.40 FPC 3.3.1
Bui Thiet
Newbie
Posts: 6
Re: Run SqlQuery1 using button
«
Reply #5 on:
February 03, 2020, 03:20:31 pm »
Thank you for your help, I have another problem, I want to create 'Save'update'Delete,', 'I'm a new person so my ability is still limited. Oh, any help would mean a lot to me. Thanks very much.
Logged
rvk
Hero Member
Posts: 6110
Re: Run SqlQuery1 using button
«
Reply #6 on:
February 03, 2020, 04:25:17 pm »
A few remarks...
An UPDATE SQL statement doesn't have := as assignment.
So it is
Code: SQL
[Select]
[+]
[-]
UPDATE
Danhmuc
SET
St
=
:Stt
,
etc
Note that the :Stt is in place of the parameter (that's what the : prefix is for) and there is no : before the =
But... you don't need all that.
If all is correct, the SQLQuery1.DeleteSQL and SQLQuery1.InsertSQL should already be set automatically.
So you can just do the following.
(and because you are using TDBEdits you don't need to use ParamByName etc.)
Code: Pascal
[Select]
[+]
[-]
procedure
Tfrmdanhmuc
.
ButtonDeleteClick
(
Sender
:
TObject
)
;
begin
SQLQuery1
.
Delete
;
end
;
procedure
Tfrmdanhmuc
.
ButtonDeleteClick
(
Sender
:
TObject
)
;
begin
SQLQuery1
.
Insert
;
// a new row is inserted
// everything you change now in the DBGrid will be changed
// and you need to press a Update-button to really post the changes
end
;
procedure
Tfrmdanhmuc
.
ButtonDeleteClick
(
Sender
:
TObject
)
;
begin
SQLQuery1
.
Post
;
SQLQuery1
.
ApplyUpdates
;
end
;
Logged
JanRoza
Hero Member
Posts: 672
Re: Run SqlQuery1 using button
«
Reply #7 on:
February 03, 2020, 04:54:17 pm »
Bui Thiet,
See this sample project
https://www.silentwings.nl/data/Kaartenbak.zip
which is a simple cardfile system using SQLite that I used in a magazine tutorial some years ago.
Comments are in Dutch I'm afraid but It might help you a bit anyway.
Logged
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
Lazarus 3.2 FPC 3.2.2
CodeTyphon 8.40 FPC 3.3.1
Bui Thiet
Newbie
Posts: 6
Re: Run SqlQuery1 using button
«
Reply #8 on:
February 04, 2020, 06:05:48 am »
Thank you all, I will do it now.
Logged
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
Databases
»
Run SqlQuery1 using button
TinyPortal
© 2005-2018