• delphi 连接数据库


    unit Unit1;

    interface

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, DB, ADODB, ExtCtrls;

    type
      TForm1 = class(TForm)
        ADOConnection1: TADOConnection;
        Button1: TButton;
        Edit1: TEdit;
        GroupBox1: TGroupBox;
        Label1: TLabel;
        Label2: TLabel;
        Label3: TLabel;
        Label4: TLabel;
        user: TEdit;
        pass: TEdit;
        database: TEdit;
        port: TEdit;
        rlogin: TButton;
        Button2: TButton;
        Label5: TLabel;
        ip: TEdit;
        top: TPanel;
        procedure dbconn();
        procedure mshow(str:string);
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure rloginClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;

    var
      Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.dbconn;
    begin
    try
    adoconnection1.Connected:=false;
    adoconnection1.Close;
    adoconnection1.ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID='+user.Text+';Initial Catalog='+database.Text+';Data Source='+ip.Text+','+port.Text+';password='+pass.Text;
    adoconnection1.Connected:=true;
    rlogin.Enabled:=true;
    except
    rlogin.Enabled:=false;
    mshow('连接数据库出现错误!!');
    end;
    end;
    procedure TForm1.mshow(str:string);
    begin
    showmessage(str);
    end;

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    mshow(Edit1.text);
    end;

    procedure TForm1.Button2Click(Sender: TObject);
    begin
    DBconn();
    end;
    procedure TForm1.rloginClick(Sender: TObject);
    begin
    try
    adoconnection1.Connected:=false;
    adoconnection1.Close;
    rlogin.Enabled:=false;
    except
    showmessage('断开数据库连接时出现错误!!');
    end;
    end;

    end.

  • 相关阅读:
    工程事故与现实世界(续)
    工程事故与现实世界
    直觉与概率
    有一种冲动:世界那么大
    人生的意义
    这些年来什么才是最好的投资?
    时间太少,如何阅读?
    程序员的成长法则与进阶攻略
    秘密:从程序员到领导者的微妙之处
    为什么加入付费社群?
  • 原文地址:https://www.cnblogs.com/smallmuda/p/1398065.html
Copyright © 2020-2023  润新知