function Tform1.updatetable(ados:Tadoquery;lcTable:string):Boolean;<br>var<br> i:integer;<br> msql:string;<br> lnparm:string;<br> lnkey:variant;<br> msql1,msql2,msql3:string;<br> adod:Tadoquery;<br>// lcold,lcnew:variant;<br>begin<br> lnparm:='';<br> msql:='';<br> adod:=Tadoquery.Create(nil);<br> adod.Connection:=form1.ADOConnection1;<br> adod.Close;<br> adod.SQL.Clear;<br> lnkey:=ados.Fields[0].AsInteger;<br> if (lnkey>0) then<br> begin<br> msql1:='update '+lcTable +' set ';<br> msql2:='';<br> msql3:='';<br> for i:=1 to ados.FieldCount-1 do<br> if ((copy(ados.Fields.FieldName,0,2) <> 'tmp') and (ados.Fields.FieldName <> 'iren') and (ados.Fields.FieldName <> 'idate') and (ados.Fields.FieldName <> 'uren') and (ados.Fields.FieldName <> 'udate')) then<br> begin<br> if ados.Fields.OldValue<>ados.Fields.Value then ----> ERROR "Invaild variant operation" please help me<br> msql2:=msql2+ados.Fields.FieldName+'=:'+ados.Fields.FieldName+',';<br> end;<br> // end;<br> msql2:=copy(trim(msql2),0,length(trim(msql2))-1);<br> if (length(msql2) <> 0) then<br> begin<br> msql1:=msql1+msql2+',uren=:uren,udate=:udate where id=:id';<br> adod.SQL.add(msql1);<br> for i:=1 to ados.FieldCount-1 do<br> begin<br> if ((copy(ados.Fields.FieldName,0,2) <> 'tmp') and (ados.Fields.FieldName <> 'iren') and (ados.Fields.FieldName <> 'idate') and (ados.Fields.FieldName <> 'uren') and (ados.Fields.FieldName <> 'udate')) then<br> begin<br> if [red]ados.Recordset.Fields.OriginalValue<>ados.Recordset.Fields.Value[/red] then ---<br> begin<br> lnparm:=ados.Fields.FieldName ;<br> adod.Parameters.ParamByName(lnparm).Value:=ados.Fields.Value;<br> end;<br> end; <br> end;<br> adod.Parameters.ParamByName('uren').Value :='admin';<br> adod.Parameters.ParamByName('udate').Value:=now();<br> adod.Parameters.ParamByName('id').value:=ados.Fields[0].Value;<br> adod.Prepared:=true;<br> try<br> adod.ExecSQL;<br> result:=true;<br> except<br> result:=false;<br> end;<br> adod.Free;<br> end;<br> end<br> else<br> begin<br> msql1:=' insert into '+lcTable+ '(';<br> for i:=1 to ados.FieldCount-1 do<br> begin<br> if ((copy(ados.Fields.FieldName,0,2) <> 'TMP') and (ados.Fields.FieldName <> 'UREN') and (ados.Fields.FieldName <> 'UDATE')) then<br> begin<br> msql2:=msql2+ ados.Fields.FieldName+',';<br> msql3:=msql3+':'+ados.Fields.FieldName+',';<br> end;<br> end;<br> msql2:=copy(trim(msql2),0,length(trim(msql2))-1);<br> msql3:=copy(trim(msql3),0,length(trim(msql3))-1);<br> msql:=msql1+msql2+') values('+msql3+')';<br> adod.SQL.Add(msql);<br> for i:=1 to ados.FieldCount-1 do<br> begin<br> if ((copy(ados.Fields.FieldName,0,2) <> 'TMP') and (ados.Fields.FieldName <> 'UREN') and (ados.Fields.FieldName <> 'UDATE')) then<br> begin<br> lnparm:=ados.Fields.FieldName ;<br> adod.Parameters.ParamByName(lnparm).Value:=ados.Fields.Value;<br> end;<br> end;<br> adod.Prepared:=true;<br> try<br> adod.ExecSQL;<br> result:=true;<br> except<br> result:=false;<br> end;<br> adod.Free;<br> end;<br> end;