在窗体上放一个table,query,两个datasource,一个edit,一个dbedit,一个button,一个dbgrid组件,我想完成这样的功能:在edit组件中输入要查询的相关信息,点击button在DBGRID和DBEDIT组件中显示相关的数据资料,然后在DBEDIT组件中修改相关的资料,请大家帮我看看我的代码对么:
procedure TForm1.Button1Click(Sender: TObject);
begin
if not table1.Locate('姓名',edit1.Text,[locaseinsensitive]) then
showmessage('没有这个人!')
else
begin
query1.Close;
query1.ParamByName('name').AsString:=edit1.Text;
query1.Open;
end;
table1.FieldByName('姓名').AsString:=query1.FieldByName('姓名').AsString; table1.Edit;
table1.FieldByName('姓名').AsString:=dbedit1.Text;
table1.Post;
query1.ParamByName('姓名').AsString:=dbedit1.Text;
end;
我一运行就提示说'table1:dataset not in insert or edit mode'我不知道是那里错了啊??请大家教我!!:)
(最好能附上代码!!!!谢谢了!!)
procedure TForm1.Button1Click(Sender: TObject);
begin
if not table1.Locate('姓名',edit1.Text,[locaseinsensitive]) then
showmessage('没有这个人!')
else
begin
query1.Close;
query1.ParamByName('name').AsString:=edit1.Text;
query1.Open;
end;
table1.FieldByName('姓名').AsString:=query1.FieldByName('姓名').AsString; table1.Edit;
table1.FieldByName('姓名').AsString:=dbedit1.Text;
table1.Post;
query1.ParamByName('姓名').AsString:=dbedit1.Text;
end;
我一运行就提示说'table1:dataset not in insert or edit mode'我不知道是那里错了啊??请大家教我!!:)
(最好能附上代码!!!!谢谢了!!)
begin
if not table1.Locate('姓名',edit1.Text,[locaseinsensitive]) then
showmessage('没有这个人!')
else
begin
query1.Close;
query1.ParamByName('name').AsString:=edit1.Text;
query1.Open;
end; table1.edit; ////這里要 加
table1.FieldByName('姓名').AsString:=query1.FieldByName('姓名').AsString; table1.Edit;
table1.FieldByName('姓名').AsString:=dbedit1.Text;
table1.Post;
//query1是一個只讀數據集﹐最好不要這樣用。
query1.ParamByName('姓名').AsString:=dbedit1.Text;
end;
table1.edit; ////這里要 加??????
要加什么啊??
真是晕~~~~~~~~~~~~~~~~~~~~~~
query1.Close;
??
query1.ParamByName('name').AsString:=edit1.Text;
query1.Open;
////////////////////////////////////////
procedure TForm1.Button1Click(Sender: TObject);
begin
if not table1.Locate('姓名',edit1.Text,[]) then
showmessage('没有这个人!')
else
begin
query1.Close;
query1.SQL.Clear; //这里!!
query1.SQL.Add(''); //这里!!
query1.ParamByName('name').AsString:=edit1.Text;
query1.Open;
end;
table1.Edit;
table1.FieldByName('姓名').AsString:=query1.FieldByName('姓名').AsString; //table1.Edit;//这里不需要!!
table1.FieldByName('姓名').AsString:=dbedit1.Text;
table1.Post;
query1.ParamByName('姓名').AsString:=dbedit1.Text;//??
end;
2.加一个UpdateSQL控件,并且将Query的ChachedUpdates=True