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
Colore celle StringGrid
by
JuanBell
[
Today
at 10:37:56 pm]
FpDebug likely bug
by
440bx
[
Today
at 10:12:59 pm]
Any upgrades to fpWeb pag...
by
verasan
[
Today
at 10:11:46 pm]
Web Applications with Pas...
by
Handoko
[
Today
at 08:56:29 pm]
AI, NLP and CAI: Text Gen...
by
indydev
[
Today
at 08:54:00 pm]
Offical launch of the 1 B...
by
Gustavo 'Gus' Carreno
[
Today
at 08:48:22 pm]
Multidimensional arrays a...
by
KodeZwerg
[
Today
at 08:34:38 pm]
Ho Ho Ho IntraWeb in Laza...
by
Thaddy
[
Today
at 08:31:29 pm]
[SOLVED] System.Now gives...
by
alpine
[
Today
at 08:29:19 pm]
open dialog - default dir...
by
Nicole
[
Today
at 08:02:40 pm]
Installing and using Vamp...
by
Odacir
[
Today
at 07:58:22 pm]
Demo Scene Picture sinwav...
by
circular
[
Today
at 07:27:02 pm]
Demo Scene Bitmap Font Sc...
by
KodeZwerg
[
Today
at 07:21:14 pm]
what's difference between...
by
ASerge
[
Today
at 07:09:52 pm]
splitting an image
by
KodeZwerg
[
Today
at 07:07:21 pm]
Debugger error
by
bobonwhidbey
[
Today
at 07:03:07 pm]
How to: create DLL file f...
by
paule32
[
Today
at 07:02:31 pm]
Your best UI design - con...
by
circular
[
Today
at 06:48:12 pm]
Converting a string/index...
by
1HuntnMan
[
Today
at 06:35:19 pm]
Drawing grid lines on a t...
by
KodeZwerg
[
Today
at 05:42:19 pm]
Compile/Convert Delphi pr...
by
Martin_fr
[
Today
at 05:29:03 pm]
Lazarus features in a non...
by
Lutz Mändle
[
Today
at 05:26:34 pm]
Lazarus for Windows on aa...
by
msintle
[
Today
at 05:03:57 pm]
Parameter passing odditie...
by
KodeZwerg
[
Today
at 03:41:49 pm]
Surf Units in Text Mode I...
by
mosquito
[
Today
at 01:58:21 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Run SqlQuery1 using button (Read 3247 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: 6171
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