我在学习中刚学会运用ADOQuery实现查找的功能:
procedure TForm1.Button1Click(Sender: TObject);
begin
ADOQuery4.SQL.Clear;
ADOQuery4.SQL.Add('select * from KAOZHENG where 学号 like'+#39+#37+edit1.Text+#37+#39);
ADOQuery4.Open;
end;
但是!~我要在Button2中实现添加或修改功能的时候我就手足无策了!
请大家帮我说明一下,谢谢!~
procedure TForm1.Button1Click(Sender: TObject);
begin
ADOQuery4.SQL.Clear;
ADOQuery4.SQL.Add('select * from KAOZHENG where 学号 like'+#39+#37+edit1.Text+#37+#39);
ADOQuery4.Open;
end;
但是!~我要在Button2中实现添加或修改功能的时候我就手足无策了!
请大家帮我说明一下,谢谢!~
begin
ADOQuery4.SQL.Clear;
ADOQuery4.SQL.Add('update KAOZHENG set 学号=#39+edit1.Text+#39 );
ADOQuery4.Open;
end;
begin
ADOQuery1.SQL.Add('select * from 表名');
ADOQuery1.Open;
ADOQuery1.Edit;
ADOQuery1['字段名']:=Edit1.Text;
ADOQuery1.Post;
end;
ADOQuery1.AppendRecord(['对应字段的数据,以逗号分隔']);
ADOQuery4.SQL.Add('insert KAOZHENG([field1],[field2]) values(''a'',''b'') ' );
ADOQuery4.ExecSql;
添加:
ADOQuery1.SQL.Add('select * from 表名');
ADOQuery1.Open;
ADOQuery1.Append; /////////////添加记录使用的方法
ADOQuery1['字段名']:=Edit1.Text;
ADOQuery1.Post;
修改:
ADOQuery1.SQL.Add('select * from 表名');
ADOQuery1.Open;
ADOQuery1.Edit; /////////////修改记录使用的方法
ADOQuery1['字段名']:=Edit1.Text;
ADOQuery1.Post;
或者你可以用SQL语句实现:
添加:
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('insert 表名(字段名1,字段名1)values(''a'',''b'') ' );
ADOQuery1.ExecSql;
修改:
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('update 表名 set 字段名1=''a''' );
ADOQuery1.ExecSql;
ADOQuery1.SQL.Add('select * from 表名');
ADOQuery1.Open;
ADOQuery1.Edit; /////////////修改记录使用的方法
ADOQuery1['字段名']:=Edit1.Text;
ADOQuery1.Post;
------------------------------------------------------------
如楼上的修改方法,会把完全相同的数据记录都一同修改了!怎么解决?