var
ADO: TADOQuery;
ADOConn: TADOConnection;
//---------------建立ADO
ADO := TADOQuery.Create;
*****************************************************************************
Bof Eof // 头尾指针
while not Eof do
begin
cbStandardNO.Items.Add(FieldByName('STANDARDNO').AsString);
Next;
end;
*****************************************************************************
***ADO链接数据库
// 在ADOConn的属性中设置LoginPrompt为False Connected为Fasle
S := 'Provider=OraOLEDB.Oracle.1;Password=' + SPassword +
';Persist Security Info=True;User ID=' + SUserName +
';Data Source=' + SIP;+';PLSQLRSET=1'//--------返回数据集 PLSQLRSET=1
try
ADOConn.Connected := false;
ADOConn.ConnectionString := S;
ADOConn.Connected := true;
except
end;
ADO.Connection := ADOConn;
*****************************************************************************
//------------------------------------------------------------------------------查询
with ADO do
begin
if Active then Close;
SQL.Text := 'SELECT KEYWORD FROM TELEGRAMPLTCM WHERE ' +
' TELEGRAMID=:TELEGRAMID AND REC_NO > (SELECT REC_NO FROM TELEGRAMPLTCM ' +
'WHERE KEYWORD = :KEYWORD AND TELEGRAMID = 1001)';
Parameters.ParamByName('KEYWORD').Value := CoilNo;
Parameters.ParamByName('TELEGRAMID').Value := 1001;
Open;
iCount := RecordCount;
end;
//-----------------------循环得到值
for i := 0 to iCount-1 do
begin
Application.ProcessMessages;
KEYWORD := FieldByName('KEYWORD').AsInteger;
tr.TelID := FieldByName('TELEGRAMID').AsInteger;
Next;
end;
//--更新 删除
try
with ADO do
begin
if Active then Close;
SQL.Text := 'UPDATE PLANCOIL SET L2TAG=:L2TAG,L2ERROR=:L2ERROR WHERE COILNO=:COILNO';
Parameters.ParamByName('L2TAG').Value := 1;
Parameters.ParamByName('L2ERROR').Value := Spare;
Parameters.ParamByName('COILNO').Value := CoilNo;
ExecSQL;
Result := True;
end;
except
on E: Exception do
ErrorText := E.Message;
end;
//-------------释放ADO
FreeAndNil(ADO);
*****************第二种方法Open;EDIT;DELETE;LOCATE;
//-----------------------------------------------------------------插入
try
with ADOQuery1 do
begin
Close;
SQL.Text:= 'select * from coilqm where rownum = 1 ';
Open;
Append;
FieldByName('COILNO').Value:= '9A0054';
FieldByName('QMRESULT').Value:= 0;
FieldByName('CHECKER').Value:= '张三';
FieldByName('CHECKTIME').Value:= now;
FieldByName('MEMO').Value:= 'NG';
Post;
end;
finally
end;
//-----------------------------------------------------------------修改
try
with ADOQuery1 do
begin
Close;
SQL.Text:= 'select * from coilqm where rownum = 1 ';
Open;
EDIT;
FieldByName('COILNO').Value:= '9A0054';
FieldByName('QMRESULT').Value:= 9;
FieldByName('CHECKER').Value:= '张三';
FieldByName('CHECKTIME').Value:= now;
FieldByName('MEMO').Value:= 'NG';
Post;
end;
finally
end;
//---------------------------------------------------------------删除
try
with ADOQuery1 do
begin
Close;
SQL.Text:= 'select * from coilqm where rownum = 1 ';
Open;
DELETE;
end;
finally
end;
//--------------------------------------------------------------查询
try
with ADOQuery1 do
begin
Close;
SQL.Text:= 'select * from coilqm where rownum = 1 ';
Open;
LOCATE('COILNO','9A0054',[loCaseInsensitive,loPartialKey]);
ShowMessage(FieldByName('CHECKER').Value);
end;
finally
end;