Delphi SQL查詢例子,模擬的SQL查詢分析器的功能,若數據庫連接正確,SQL順利執行的話,會看到數據顯示,統計出記錄集條數,Delphi高手請跳過。
01
unit
Unit1;
02
interface
03
uses
04
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
05
Dialogs, StdCtrls, ComCtrls, DB, ADODB, ExtCtrls, Grids, DBGrids;
06
type
07
TForm1 =
class
(TForm)
08
GroupBox1: TGroupBox;
09
EditSQL: TEdit;
10
ButtonSQL: TButton;
11
ButtonClear: TButton;
12
DBGrid1: TDBGrid;
13
Timer1: TTimer;
14
ADOConnection1: TADOConnection;
15
ADOQuery1: TADOQuery;
16
DataSource1: TDataSource;
17
StatusBar1: TStatusBar;
18
Label1: TLabel;
19
Label2: TLabel;
20
EditTotalNum: TEdit;
21
procedure
Timer1Timer(Sender: TObject);
22
ButtonClearClick(Sender: TObject);
23
ButtonSQLClick(Sender: TObject);
24
private
25
{ Private declarations }
26
public
27
{ Public declarations }
28
end
;
29
var
30
Form1: TForm1;
31
implementation
32
{$R *.dfm}
33
TForm1
.
34
begin
35
ShortDateFormat:=
'y/m/d h:n:ss'
36
StatusBar1
Panels
Items[
0
].Text:=
'時間:'
+DateToStr(now);
37
38
39
40
EditSQL
Text:=
''
41
42
43
44
AffectRecordCount:
Integer
45
SQLString:
string
46
47
SQLString:=Trim(EditSQL
Text);
48
try
49
with
ADOQuery1
do
50
51
close;
52
sql
Clear;
53
add(SQLString);
54
if
UpperCase( copy(SQLString,
1
,
6
)) =
'SELECT'
then
55
56
open;
57
'狀態:'
+
'SELECT語句執行成功,返回記錄總數:'
58
+IntToStr(RecordCount);
59
EditTotalNum
Text:=IntToStr(RecordCount);
60
61
else
62
63
AffectRecordCount:=ExecSQL;
64
'SQL語句執行成功,受影響記錄個數:'
65
+IntToStr(AffectRecordCount);
66
MessageDlg(
'需要提取更新的數據嗎?'
,mtInformation,[mbYes,mbNo],
)=mrYes
67
68
69
70
add(
'select * from Contact'
);
71
72
73
74
75
76
except
77
on
E:Exception
78
79
'SQL語句執行失敗--'
+e
Message;
80
Exit;
81
82
83
84
Delphi7的HtmlParser使用方法,delphi7
StartCap 和 EndCap 屬性分別用來讀寫兩段的
Delphi與DirectX之DelphiX(
、最近在寫I2C下EEPROM的驅動程序,但發現使用i
Delphi枚舉當前所有的顯示模式,並通過拖動滑塊的方式來