Advertisement
X-88

Ado Connection

Apr 5th, 2021
1,736
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.40 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, DB, ADODB, StdCtrls, Grids, DBGrids, AdoConEd, XPMan;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     AC: TADOConnection;
  12.     EP: TEdit;
  13.     AT: TADOTable;
  14.     ET: TEdit;
  15.     DS: TDataSource;
  16.     DBGrid1: TDBGrid;
  17.     Button1: TButton;
  18.     procedure Button1Click(Sender: TObject);
  19.     procedure FormActivate(Sender: TObject);
  20.   private
  21.     { Private declarations }
  22.   public
  23.     { Public declarations }
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.dfm}
  32.  
  33. procedure TForm1.Button1Click(Sender: TObject);
  34. begin
  35.    AC.Close;
  36.    AC.ConnectionString := EP.Text;
  37. if EditConnectionString(AC) then
  38. begin
  39.    EP.Text := AC.ConnectionString;
  40.    AT.ConnectionString := EP.Text;
  41.    AT.TableName := ET.Text;
  42.    AC.Connected := true;
  43.    AT.Active := true;
  44.    Caption := AC.DefaultDatabase;
  45. end;
  46. end;
  47.  
  48. procedure TForm1.FormActivate(Sender: TObject);
  49. var
  50.    Path : String;
  51. begin
  52.    Path := ExtractFilePath(Application.ExeName)+'ZS.mdb';
  53. if not FileExists(Path) then
  54.    exit
  55. else
  56.    AC.Close;
  57.    AC.LoginPrompt := false;
  58.    EP.Text := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+Path+';Persist Security Info=False';
  59.    AC.ConnectionString := EP.Text;
  60.    AT.ConnectionString := EP.Text;
  61.    AT.TableName := ET.Text;
  62.    AC.Connected := true;
  63.    AT.Active := true;
  64.  
  65. end;
  66.  
  67. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement