这是我的代码
object Form1: TForm1
Left = 192
Top = 107
Width = 450
Height = 417
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button3: TButton
Left = 64
Top = 352
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button3Click
end
object DBGrid1: TDBGrid
Left = 0
Top = 0
Width = 442
Height = 329
Align = alTop
DataSource = DataSource1
TabOrder = 1
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object ADOConnection1: TADOConnection
Connected = True
ConnectionString =
'Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security In' +
'fo=False;Initial Catalog=DELPHIBBS;Data Source=YONG;Use Procedur' +
'e for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation' +
' ID=YONG;Use Encryption for Data=False;Tag with column collation' +
' when possible=False'
CursorLocation = clUseServer
IsolationLevel = ilBrowse
LoginPrompt = False
Mode = cmShareDenyNone
Provider = 'SQLOLEDB.1'
Left = 48
Top = 56
end
object DataSource1: TDataSource
DataSet = ADODataSet1
Left = 88
Top = 112
end
object ADODataSet1: TADODataSet
Active = True
Connection = ADOConnection1
CursorLocation = clUseServer
CommandText = 'select * from letters'
Parameters = <>
Left = 32
Top = 112
end
end
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, Wwdbigrd, Wwdbgrid, Db, StdCtrls, ADODB, Mask, DBCtrls, ComCtrls,
DBGrids;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
DataSource1: TDataSource;
Button3: TButton;
ADODataSet1: TADODataSet;
DBGrid1: TDBGrid;
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button3Click(Sender: TObject);
begin
if adoconnection1.InTransaction then adoconnection1.CommitTrans;
ADOConnection1.BeginTrans;
try
ADODataSet1.Edit;
ADODataSet1.Fields[3].AsString:='bbbbbbbbbb';
ADODataSet1.Post;
adoconnection1.CommitTrans;
except
adoconnection1.RollbackTrans;
end;
end;
end.