国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Delphi > 正文

delphi7連接mysql5的實現方法

2020-01-31 20:51:35
字體:
來源:轉載
供稿:網友

本文簡單介紹了Delphi7連接MySQL數據庫的實現方法,具體步驟如下:

首先先去下載:http://www.justsoftwaresolutions.co.uk/delphi/dbexpress_and_mysql_5.html

然后將下載到的dbxopenmysql5_dll.zip解壓出來,再把dbxopenmysql50.dll和libmysql.dll都放到工程文件夾下。

在Form上放上TSQLConnection、TSQLQuery、TStringGrid、3個TButton、TLable。

添加如下代碼:

unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DBXpress, FMTBcd, StdCtrls, Grids, DB, SqlExpr;type TForm1 = class(TForm)  SQLConnection1: TSQLConnection;  SQLQuery1: TSQLQuery;  StringGrid1: TStringGrid;  Button1: TButton;  Button2: TButton;  Button3: TButton;  Label1: TLabel;  procedure Button1Click(Sender: TObject);  procedure Button2Click(Sender: TObject);  procedure Button3Click(Sender: TObject); private  { Private declarations } public  { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject);begin SQLConnection1 := TSQLConnection.Create(nil); SQLConnection1.DriverName := 'dbxmysql'; SQLConnection1.GetDriverFunc := 'getSQLDriverMYSQL50'; SQLConnection1.LibraryName := 'dbxopenmysql50.dll'; SQLConnection1.VendorLib := 'libmysql.dll'; SQLConnection1.LoginPrompt := false; SQLConnection1.Params.Append('Database=mysql'); SQLConnection1.Params.Append('User_Name=root'); SQLConnection1.Params.Append('Password='); SQLConnection1.Params.Append('HostName=localhost'); SQLConnection1.Open; if SQLConnection1.Connected = true then begin  SQLQuery1.SQLConnection := SQLConnection1;  Label1.Caption := 'success!'; end else  Label1.Caption := 'failed!';end; procedure TForm1.Button2Click(Sender: TObject);var i, j: Integer;begin  SQLQuery1.SQL.Clear; SQLQuery1.SQL.Add('SELECT * FROM user'); SQLQuery1.Active := true; i := 0; SQLQuery1.First; while not SQLQuery1.eof do begin  for j := 0 to SQLQuery1.FieldCount - 1 do   StringGrid1.cells[j, i] := SQLQuery1.Fields[j].AsString;  SQLQuery1.next;  inc(i); end; SQLQuery1.Active := false;end; procedure TForm1.Button3Click(Sender: TObject);begin if SQLConnection1.Connected = true then  SQLConnection1.Close; SQLConnection1.Free;end; end.  

經測試,可實現正常連接與查詢。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 彭阳县| 垣曲县| 南溪县| 道孚县| 屏东县| 扶余县| 广西| 庐江县| 永靖县| 呼图壁县| 滦平县| 横峰县| 鄢陵县| 泰和县| 三门县| 叶城县| 广安市| 昌图县| 高雄市| 白朗县| 彭泽县| 巴彦县| 彰化市| 多伦县| 三台县| 库车县| 托克托县| 黄浦区| 县级市| 保德县| 泰顺县| 南丰县| 昌都县| 开平市| 大宁县| 东兰县| 通化市| 潮安县| 本溪| 新郑市| 兴仁县|