关于数据库中数据修改问题,在线等,速结贴。

masepu 2003-10-08 07:23:58
实现如下功能:
用户输入用户名(edit1)和旧密码(edit2),经过验证通过后判断用户输入的两次新密码(edit3,edit4)是否一致,然后更改数据库中存的密码。但更改密码处出错,提示:'table1:Cannot perform this operation on an open dataset'.代码如下:
begin
DataModule2.Table1.Active := true;
with DataModule2.Table1 do
begin
SetKey;
FieldByName('userID').AsString:=Edit1.Text;
if GotoKey then
begin
if Locate('password',VarArrayOf([Edit2.Text]),[]) then
begin
if edit3.Text = edit4.Text then
begin
showmessage('ok');
unit2.DataModule2.Table1.Active := true;
unit2.DataModule2.Table1.ReadOnly := false;
unit2.DataModule2.Table1.Edit;
unit2.DataModule2.Table1.FieldByName('password').AsString:=Edit3.Text; // 设置具体数值
unit2.DataModule2.Table1.Post; // 写回数据库
unit2.DataModule2.Table1.Refresh;
end;
end
else
showmessage('password error');
end
else
showmessage('error');
end;
end;
望高手指点,先谢过,在线等,速结贴。
...全文
42 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ggdw 2003-10-08
  • 打赏
  • 举报
回复
用ADOQUERY,简单方便
DataModule2.adoquery.clear;
DataModule2.adoquery.open;
DataModule2.adoquery.sql.text:=select * from table update table set 密码='''+密码.text+'''where 用户名='''+用户名+''' and 旧密码='''+bh+'''';
data.nyq.open;
huojiehai 2003-10-08
  • 打赏
  • 举报
回复
Note: Even if ReadOnly is False, users may not be able to modify or add data to a table. Other factors, such as insufficient SQL privileges for the application or its current user may prevent successful alterations.

To guarantee that users cannot modify or add data to a table,

1 Set the Active property to False.
2 Set ReadOnly to True.

When ReadOnly is True, the table抯 CanModify property is False.
huojiehai 2003-10-08
  • 打赏
  • 举报
回复
//unit2.DataModule2.Table1.ReadOnly := false;//这句话不能在数据集打开的情况下执行,应去掉

5,930

社区成员

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

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