为什么不能提交,我很急,谢谢!(在线等待) (200分)

  • 主题发起人 主题发起人 yongshiok
  • 开始时间 开始时间
应该和你的程序无关,我觉得是数据库的问题。
SQL Server以前用的时候没有发现这个问题,无论是设置CursorLocation在那边。
 
your app is error just because your CursorLocation is clUseServer.
error string: Dataset does not support bookmarks, which are required
for multi-record data record。

test enviroment: win2K, sql 7, Delphi 5 with update, adoupdate1,2.
 
to bluerain
我的没有这个问题“Dataset does not support bookmarks, which are required for multi-record data
record ”

test enviroment : win2K, sql 2k, Delphi 5 with update, adoupdate1,2.

 
这是我的代码
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.
 
sorry, 我搞错了。我想是你是用dbgrid来显示记录的吧,如果是的话,问题出在这里。
下面是我的实验:
===== sql server ====
建一个表testtbl
字段为 id int identity
name varchar
随便输一些记录

===== delphi =====

adodataset1.CommandText := 'select * from testtbl';
adodataset1.Open;
adodataset1.First;
ADOConnection1.BeginTrans;
try
ADODataSet1.Edit;
ADODataSet1.Fields[1].AsString := 'bbbbbbbbbb';
ADODataSet1.Post;
adoconnection1.CommitTrans;
except
adoconnection1.RollbackTrans;
end;

其中 adodataset1的cursorlocation为crUseServer

===== result =====
1。放一个datasource,dbgrid, dbgird。datasource = datasource1,
datasource1。dataset = adodataset1;
出错,出错原因见上一贴

2。去掉datasource和dbgrid, 没有问题。



 
也就是说,并不是adodataset对cursorlocation敏感,而是dbgrid对此敏感。
 
已经搞定
结贴,谢谢各位!
 
多人接受答案了。
 
后退
顶部