Delphi uses dbexpress component to connect remote MySQL database

Source: Internet
Author: User
Tags mysql database

Delphi6 's new dbexpress is specifically designed to deal with databases such as mysql,db2,interbase,oracle, and when used, take care to copy Libmysql.dll to the current directory or system directory (98:SYSTEM,NT:SYSTEM32) and ensure that your 3306 ports are connected to the remote server.

SOURCE program:

Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Dbxpress, DB, sqlexpr, Stdctrls, Comctrls, FMTBCD, Grids,
Dbgrids, Provider, Dbclient, dblocal, Dblocals, dbtables;
Type
TForm1 = Class (Tform)
Sqlconnection:tsqlconnection;
Statusbar1:tstatusbar;
Label1:tlabel;
Datasource1:tdatasource;
Dbgrid1:tdbgrid;
Groupbox1:tgroupbox;
Label2:tlabel;
Password:tedit;
User_name:tedit;
Hostname:tedit;
Label3:tlabel;
Label4:tlabel;
Button1:tbutton;
Groupbox2:tgroupbox;
Label5:tlabel;
Esql:tedit;
Label6:tlabel;
Database:tedit;
Buttongo:tbutton;
Sqlclientdataset:tsqlclientdataset;
Procedure Button1Click (Sender:tobject);
Procedure Buttongoclick (Sender:tobject);
Procedure Formclose (Sender:tobject; var action:tcloseaction);
Private
{Private declarations}
Public
{Public declarations}
End
Var
Form1:tform1;
Implementation
{$R *.DFM}
Procedure Tform1.button1click (Sender:tobject);
Begin
With SqlConnection do
Begin
Close;
params.values[' HostName ']:=hostname.text;
params.values[' UserName ']:=user_name.text;
params.values[' Password ']:=password.text;
params.values[' Database ']:=database.text;
Try
Connected:=true;
Statusbar1.panels[0]. text:= ' Connect OK ';
Buttongo.enabled:=true;
Except
Messagedlg (' Connect Error ', mterror,[mbyes],0);
End
End
End
Procedure Tform1.buttongoclick (Sender:tobject);
Begin
With Sqlclientdataset do
Begin
Close;
Commandtext:=esql. Text;
Open;
End
End
Procedure Tform1.formclose (Sender:tobject; var action:tcloseaction);
Begin
Sqlconnection.close;
End
End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.