最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

delphi7連接mysql5的實(shí)現(xiàn)方法

 更新時(shí)間:2014年07月17日 09:32:51   投稿:shichen2014  
這篇文章主要介紹了delphi7連接mysql5的實(shí)現(xiàn)方法,需要的朋友可以參考下

本文簡(jiǎn)單介紹了Delphi7連接MySQL數(shù)據(jù)庫(kù)的實(shí)現(xiàn)方法,具體步驟如下:

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

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

在Form上放上TSQLConnection、TSQLQuery、TStringGrid、3個(gè)TButton、TLable。

添加如下代碼:

unit Unit1;
interface
uses
 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.
  

經(jīng)測(cè)試,可實(shí)現(xiàn)正常連接與查詢。

相關(guān)文章

最新評(píng)論

朝阳市| 阿拉尔市| 阿勒泰市| 洛南县| 密山市| 桦南县| 龙里县| 张北县| 肥乡县| 永寿县| 白玉县| 竹山县| 望奎县| 西安市| 鄂托克前旗| 枞阳县| 长子县| 富宁县| 文成县| 南郑县| 方正县| 沅陵县| 精河县| 河津市| 凌云县| 府谷县| 岳池县| 台南市| 广河县| 武邑县| 宁蒗| 五大连池市| 济源市| 中超| 虎林市| 夹江县| 宝山区| 阿鲁科尔沁旗| 金川县| 兴业县| 红原县|