zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    JavaWeb学习总结(二)——Tomcat服务器学习和使用(一)
    JavaWeb学习总结(一)——JavaWeb开发入门
    javaweb学习总结(四)——Http协议
    Eclipse中应用的调试
    Java Web快速入门——全十讲
    Spring 系列: Spring 框架简介
    分布式环境中三种Session管理方法的使用场景及优缺点
    Cookie/Session机制详解
    HTTP 协议详解
    Webx3学习笔记(2)——基本流程
  • 原文地址:https://www.cnblogs.com/smallmuda/p/1398065.html
Copyright © 2011-2022 走看看