程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> Delphi2009中使用dbExpress組件訪問MySql(登陸頁面)(2)

Delphi2009中使用dbExpress組件訪問MySql(登陸頁面)(2)

編輯:Delphi

可對Form的屬性作必要的設定(如:BorderStyle:bsDialog; Position:poDesktopCenter)

添加一個TSQLQuery控件在於其上。後台的代碼如下所示:

1.unit LoginUnit;
2.
3.interface
4.
5.uses
6. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7. Dialogs, StdCtrls, ExtCtrls, DB, ADODB, WideStrings, DBXMySQL, SqlExpr, FMTBcd,
8. DBClIEnt, SimpleDS;
9.
10.type
11. TFrmLogin = class(TForm)
12. Bevel1: TBevel;
13. Label1: TLabel;
14. Label2: TLabel;
15. Edit1: TEdit;
16. Label3: TLabel;
17. Edit2: TEdit;
18. Button1: TButton;
19. Button2: TButton;
20. LoginSQLQuery: TSQLQuery;
21. procedure Button2Click(Sender: TObject);
22. procedure Button1Click(Sender: TObject);
23. private
24. { Private declarations }
25. public
26. { Public declarations }
27. end;
28.
29.var
30. FrmLogin: TFrmLogin;
31.
32.implementation
33.
34.uses DataModuleUnit;
35.
36.{$R *.dfm}
37.
38.procedure TFrmLogin.Button1Click(Sender: TObject);
39.var
40. username, passWord : string;
41. recordcount : Integer;
42.begin
43. username := Edit1.Text;
44. passWord := Edit2.Text;
45.
46. if username = '' then
47. begin
48. ShowMessage('ユーザ名を入力してください!');
49. Edit1.SetFocus;
50. end
51. else if passWord = '' then
52. begin
53. ShowMessage('パスワードを入力してください!');
54. Edit2.SetFocus;
55. end
56. else
57. begin
58. LoginSQLQuery.SQLConnection := DataModule1.MySQLConnection;
59. LoginSQLQuery.CommandText := 'SELECT * FROM T_USR WHERE USID =' + username + ' AND PWD = ' + passWord;
60. recordcount := LoginSQLQuery.RecordCount;
61. if recordcount < 1 then
62. begin
63. ShowMessage('ユーザ名又はパスワードが違います!');
64. end
65. else66. begin
67. ShowMessage('ログインします!');
68. end;
69. end;
70.end;
71.
72.procedure TFrmLogin.Button2Click(Sender: TObject);
73.begin
74. close;
75.end;
76.
77.end.
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved