我更新一个表,从form1里的30多个edit,memo等中取内容,现在不知道用户修改了其中几个,那么我就选择全部更新到库里,写update句子的时候岂不是要写30多个字段,很麻烦啊,有简单一点的办法没有?不光是UPDATE的简单办法,整个更新的解决办法也可以
解决方案 »
- TMS控件包中的Advstringgrid使用方法
- 有关QuickReport的问题,急啊!
- TfileStream中的read函数参数疑惑?
- 我一个基于SQL SERVER2000开发的系统,平时用的好好的,今天出然在保存时跳出来一句“Non-blob column in table required to perform ope
- Chart的问题
- 另一个执行程序中有三个edit如何分别取出并确定是那一个
- 请问哪有查delphi函数的电子书下载?不要让我看帮助呀,我不懂E文
- 请教,在quickreport中如何实现每页合计?用什么控键呢???在线等待
- 你值多少钱?对照一下你的薪水多还是少了-2004年各职位工资统计表(转帖)
- Delphi Base64 and Md5 与 Java 实现相同结果?
- 如何远程添加数据
- jni求助,JVM重复创建失败
若30个都改了,就得写上30个字段更新,没其它办法!!!
我去看看dbedit这些的具体应用
只是要求edit的名字必须是:(与表名对应的)特定前缀+字段名
//新增,修改记录
//ThashTable 是我自己实现的一个key数组类
//_COUNT为特殊字段。更新自动+1
function Edit(AData: THashTable; table:string; where:string = ''):string;
var
i: integer;
Key: string;
begin
Result := '';
ConnectDatabase();
try
Form1.ADOQuery1.SQL.Text := 'select * from ' + table + where;
Form1.ADOQuery1.Open;
if where = '' then Form1.ADOQuery1.Append
else Form1.ADOQuery1.Edit;
for i := 0 to AData.Count - 1 do
begin
Key := AData.HtGetKey(i);
if Key = '_COUNT' then Form1.ADOQuery1.FieldValues[Key] := Form1.ADOQuery1.FieldByName(Key).AsInteger + 1
else Form1.ADOQuery1.FieldValues[Key] := AData.HtGet(Key);
end;
Form1.ADOQuery1.Post;
if where = '' then
begin
Form1.ADOQuery1.Last;
Result := Form1.ADOQuery1.FieldValues['ID'];
end;
finally
CloseDatabase;
end;
end;
//新增,修改记录
//THashTable 是我自己实现的一个key数组类
//_COUNT为特殊字段。更新自动+1
function Edit(AData: THashTable; table:string; where:string = ''):string;
var
i: integer;
Key: string;
begin
Result := '';
ConnectDatabase();
try
Form1.ADOQuery1.SQL.Text := 'select * from ' + table + where;
Form1.ADOQuery1.Open;
if where = '' then Form1.ADOQuery1.Append
else Form1.ADOQuery1.Edit;
for i := 0 to AData.Count - 1 do
begin
Key := AData.HtGetKey(i);
if Key = '_COUNT' then Form1.ADOQuery1.FieldValues[Key] := Form1.ADOQuery1.FieldByName(Key).AsInteger + 1
else Form1.ADOQuery1.FieldValues[Key] := AData.HtGet(Key);
end;
Form1.ADOQuery1.Post;
if where = '' then
begin
Form1.ADOQuery1.Last;
Result := Form1.ADOQuery1.FieldValues['ID'];
end;
finally
CloseDatabase;
end;
end;
先定位到当前记录,然后用
adoquery.edit;
adoquery.fieldbyname('aa').value := ....
adoquery.fieldbyname('bb').value := ....
........................................
adoquery.post;
如果改变 即adoquery.fieldbyname('aa').value := ....