unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,IniFiles, DB, ADODB, adoconed,StdCtrls, Grids, DBGrids;
type
TForm1 = class(TForm)
Adocon1: TADOConnection;
Edit1: TEdit;
Label1: TLabel;
Edit2: TEdit;
Label2: TLabel;
Button1: TButton;
Button2: TButton;
Label3: TLabel;
Edit3: TEdit;
Label4: TLabel;
Edit4: TEdit;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Edit5: TEdit;
Label5: TLabel;
AdoTable1: TADOTable;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
str1,str2:string;
begin
if (Edit1.text='') and (Edit2.text='')
and (edit3.Text='')and (edit4.text='')then
EditConnectionString(Adocon1)
else
str1:='Provider=SQLOLEDB.1;Password='+edit4.text+';Persist Security Info=True;User ID='+edit3.Text+';Initial Catalog='+edit2.Text+';Data Source='+edit1.Text;
//str2:='Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=CT;Use Encryption for Data=False;Tag with column collation when possible=False
adocon1.ConnectionString:=str1;
adocon1.Connected:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
b:integer;
begin
b:=strToint(Edit5.text);
AdoTable1.Connection:=AdoCon1;
AdoTable1.TableName:='ct_cp';
AdoTable1.Active:=true;
AdoTable1.First;
while not AdoTable1.Eof do
begin
b:=1+b;
AdoTable1.edit;
AdoTable1.FieldByName('cpbh').AsString:=inttostr(b);
AdoTable1.Next;
end;
end;
end.
应该没问题