关于查询结果并修改数据的问题

fstao 1999-12-31 12:16:00
用MSSQL7建一新表Table1,在Form1里添加Query1、Button1和button2,在query1的RequestLive设置为True,
query1的属性SQL为:select * form table1,Active设置为“True”。
在Button1的Onclick事件为:
procedure TForm1.Button1Click(Sender: TObject);
begin
query1.RequestLive :=True;
query1.Edit;
query1.FieldByName('sign').AsString:='yes';
query1.post;
end;
在Button2的Onclick事件为:
query1.RequestLive :=false;
with query1 do
begin
close;
sql.clear;
sql.add('select * from table1 where id1=:id1');
Parambyname('id1').Asinteger:=2;
open;
end;
这样运行时,按Button1,正常。如果按Button2,再来按Button1则出现错误:
Query1:Cannot modify a Read-only Dataset.
我就是在button1添加“query1.CanModify:=true;”,运行过程出现错误:
“[Error] Unit1.pas(46): Cannot assign to a read-only property”;

我这个问题是这样的,我想用SQL来查询(比如按Button2),查出来的结果再把
某些数据修改(比如按Button1),但我这样做会出现错误。请问如何必免这个错误,
或者说我要实现这种功能,如何做更好?
...全文
2107 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
渤海海峡 2000-01-04
  • 打赏
  • 举报
回复
button1Click:

with query1 do
begin
close;
RequestLive:=true;
open;
edit;
query1.FieldByName('aaa').asstring:='sdfgfdsg';
post;
end;
snow 2000-01-02
  • 打赏
  • 举报
回复
在Button1的Onclick事件为:
procedure TForm1.Button1Click(Sender: TObject);
begin
query1.close;
query1.RequestLive :=True;
query1.open;
query1.Edit;
...
kxy 1999-12-31
  • 打赏
  • 举报
回复
在Button2的Onclick事件为:
query1.RequestLive :=false;
query的结果就不能修改,button1中在设回来也没用,你为什么把
query1.RequestLive设成False呢?
button1中,如果query查询的结果为空呢.
query1.RequestLive在查询前有用,查询后,设置没有用.
fstao 1999-12-31
  • 打赏
  • 举报
回复
用MSSQL7建一表Table1,在Form1里添加Query1、Edit1和Button1,Query1的
RequestLive设置为True。在Button1的Click事件为:
with query1 do
begin
close;
sql.clear;
sql.add(Edit1.Text);
open;
end;

运行时,在Edit1里添加Sql语句:
select * from Table1 where Salary_No>='1' and Salary_No<='2' and name like 'sds' and PostalCode like '12' and Units like 'sds' and Area like 'sds' and purchase_product like 'sds' and Quantity like '12' and payment like '12' and Purment_level like '1'
按Button1出现错误:
Could not find object.

其实这句Sql语句是没有错的,在Sql Explorer通过了。但是如果把Query1的属性
ResquestLiver设置为False时,按Button1就没有错。由于我的程序的设计要求,要使
Query1既能够查询记录,也能够修改记录,所以一定要把ResquestLiver设置为True时,
但这样做就不能查询记录,只能修改记录。但如果把ResquestLiver设置为false时,
这样就可以解决查询的问题,但不能修改记录。如何做,或者说如果用TQuery,要使
它既能够用SQL语句查询,也能够修改记录,还有什么方法呢?请指教!(如果数据库是用Paradox7,
就不会出现此问题)

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧