Delphi在数据库操作是非常好用的,delphi把ADO一些方法属性都集成了,以下是我的一些总结: ******************************* 通过sql的存储过程来实现: 添加 With ADOQuery1 do begin Close; SQL.Clear; SQL.Add(' Insert Into Table1(Field1,Field2)') SQL.Add(' Values(10,20)'); ExecSQL; end;
修改 With ADOQuery1 do begin Close; SQL.Clear; SQL.Add(' Update Table1 Set Field1=20,Field2=30)') ExecSQL; end;
删除 With ADOQuery1 do begin Close; SQL.Clear; SQL.Add(' Delete From Table1') SQL.Add(' Where Field1=20 and Field2=30'); ExecSQL; end;
查询 With ADOQuery1 do begin Close; SQL.Clear; SQL.Add(' Select Field1,Field2 From Table1') SQL.Add(' Where Field1=20 and Field2=30'); Open; end; *************************************************** 通过Delphi自有的方法属性实现:
添加: with ADOQuery1 do append; ...... post; 删除: with ADOQuery1 do delete(选择删除的记录); //默认删除记录指针指向的记录 修改: with ADOQuery1 do edit; ...... post;
adotable1.Append; //添加 ADotable1.Fields.FieldByName('gxid1').Value:=gx; adotable1.Post;
adotable1.delete; //删除
adotable1.edit; //修改 ADotable1.Fields.FieldByName('gxid1').Value:=gx; adotable1.post;
WITHI adoquery do begin//添加 adoquery.open;//motice set adoquery.sql adoquery.append;//OR adoquery.insert; fieldbyname(fieldname).asstring:=trim(edit1.text); ...... adoquery.post; end;
删除: adoquery.delete
修改: adoquery.edit; fieldbyname(fieldname).asstring:=trim(edit1.text);
|
请发表评论