⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testcommand.pas

📁 delphi renyuanguanlixinxioxitong
💻 PAS
字号:
unit TestCommand;

interface

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

type
  TForm1 = class(TForm)
    ADOConnection1: TADOConnection;
    ADOCommand1: TADOCommand;
    Button1: TButton;
    ADOTable1: TADOTable;
    DBGrid1: TDBGrid;
    DataSource1: TDataSource;
    ADOCommand2: TADOCommand;
    ADODataSet1: TADODataSet;
    Button2: TButton;
    ADOQuery1: TADOQuery;
    ADOStoredProc1: TADOStoredProc;
    Button3: TButton;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if  not ADOConnection1.Connected  then
    ADOConnection1.Open ;
  try
    ADOCommand1.Connection := ADOConnection1 ;
    ADOCommand1.CommandText :='insert into DCPost values(:sPostNo,:sPostName,0)';
    ADOCommand1.Parameters.ParamByName('sPostNo').Value :='100';
    ADOCommand1.Parameters.ParamByName('sPostName').Value :='工程师';
    ADOCommand1.Execute;
  except
    ADOCommand1.Cancel;
    application.MessageBox('插入数据出错','提示错误');
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
   if  not ADOConnection1.Connected  then  ADOConnection1.Open ;
   try
     ADOCommand2.Connection := ADOConnection1;
     ADOCommand2.CommandText :='DCNation';
     ADODataSet1.Recordset := ADOCommand2.Execute;
   except
     ADOCommand1.Cancel;
     application.MessageBox('插入数据出错','提示错误');
  end;

end;
  
procedure TForm1.Button3Click(Sender: TObject);
begin
  if  not ADOConnection1.Connected  then  ADOConnection1.Open ;
  if ADOTable1.Active then ADOTable1.Close;
  try
     ADOTable1.Connection := ADOConnection1;
     ADOTable1.Open ;
     ADOTable1.Sort :='PostName';
  except
     ADOTable1.Cancel;
     application.MessageBox('排序出错','提示错误');
  end;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  if  not ADOConnection1.Connected  then  ADOConnection1.Open ;
  if ADOTable1.Active then ADOTable1.Close;
  try
     ADOTable1.Connection := ADOConnection1;
     ADOTable1.Open ;
     ADOTable1.Filter :='PostNo=001'  ;
     ADOTable1.Filtered := True;
     ADOTable1.FieldByName('NationName').Value :='总工程师';
  except
     if   ADOTable1.State <> dsBrowse then
        application.MessageBox('数据集不在修改状态,不能提交','提示错误');


     ADOTable1.Edit
     application.MessageBox('排序出错','提示错误');
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -