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
Warning: Source OS Redefi...
by
Laksen
[
Today
at 11:32:46 am]
[SOLVED] how to see what ...
by
Laksen
[
Today
at 11:30:25 am]
Slow copying of small str...
by
alpine
[
Today
at 11:25:10 am]
assembler name is longer ...
by
Key-Real
[
Today
at 11:15:20 am]
Question for people who h...
by
BrassGear
[
Today
at 11:12:50 am]
I just released a commerc...
by
BrassGear
[
Today
at 11:05:12 am]
How to: create DLL file f...
by
KodeZwerg
[
Today
at 10:53:20 am]
Assign (textfile) not com...
by
Thaddy
[
Today
at 10:51:18 am]
Text orientation in TMemo...
by
wp
[
Today
at 10:27:54 am]
InstallAware Using Lazaru...
by
marcov
[
Today
at 10:05:26 am]
Linux Workspaces -- StayO...
by
AmatCoder
[
Today
at 08:21:27 am]
Demoscene The Champs Crac...
by
Lulu
[
Today
at 08:15:12 am]
Azure sql database will n...
by
paweld
[
Today
at 07:24:47 am]
Find child controls by na...
by
Handoko
[
Today
at 04:17:05 am]
location of non visual co...
by
VisualLab
[April 17, 2024, 11:58:55 pm]
For-in loop over constant...
by
Joanna
[April 17, 2024, 11:57:15 pm]
Lazarus editor feature re...
by
440bx
[April 17, 2024, 11:49:08 pm]
How would you define a fi...
by
wp
[April 17, 2024, 11:04:00 pm]
Directx9 with mylogo insi...
by
KodeZwerg
[April 17, 2024, 11:03:54 pm]
Lazarus for Windows on aa...
by
Wallaby
[April 17, 2024, 10:25:46 pm]
[SOLVED] TDbf table, Leve...
by
1HuntnMan
[April 17, 2024, 10:03:16 pm]
Doomed name
by
Martin_fr
[April 17, 2024, 09:09:52 pm]
lazarus-project_3.2.0-0_a...
by
midigark
[April 17, 2024, 06:09:40 pm]
TBGRABitmap.TextSize retu...
by
circular
[April 17, 2024, 05:24:04 pm]
BUG REPORT: Unable to gen...
by
gasensor
[April 17, 2024, 05:10:20 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Run SqlQuery1 using button (Read 3221 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: 6163
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