//add,edit,delete operator
...
with myADOQuery do begin
Close;
//假设Field1是字符型,Field2是整型
//Add Record
SQL.Text := 'INSERT INTO YoursTableName (Field1,Field2) VALUES('ABC',123)';
//Edit record
//SQL.Text := 'UPDATE YoursTableName Set Field1 = ''a'',Field2 = 345' +
// ' WHERE Field2 = 123';//conditions you need
//Delete record
//SQL.Text := 'DELETE FROM YoursTableName WHERE Field2 = 123';
Prepared;
ExecSQL;
Close;
ShowMessage('OK!');
end;
//假设用TADOQUERY控件查询SQL SERVER数据库中某个表(表名假设为YoursTableName),将该
//表中的字段,——假设叫FieldName值全部查询出来并加到LISTBOX控件中。
procedure OperatorSQLServerWithADO;
var
myADOQuery:TADOQuery;
begin
myADOQuery := TADOQuery.Create(nil);
myADOQuery.ConnectionString := 'Provider=SQLOLEDB.1;Persist Security
Info=True;User ID=sa;Initial Catalog=Ex;Data
Source=SMALLBRIDGE';
try
with myADOQuery do begin
Close;
SQL.Text := 'SELECT * FROM YoursTableName';
Open;
if IsEmpty then begin Close; Exit; end;
ListBox1.Items.Clear;
while not Eof do begin
ListBox1.Items.Add(TRIM(FieldByName('FieldName').AsString)); //Fields
Next;
end;
Close;
end;
finally
myADOQuery.Free;
end;
end;