memo1.lines.clear; memo1.lines.add('********数据表原有的内容如下********'); {显示各个域的域名} strTemp := '; for intIndex := 0 to ARecordSet.Fields.count - 1 do strTemp := strTemp + ARecordSet.Fields[intIndex].name+';'; memo1.lines.add( strTemp );
{显示各个域的内容} while not ARecordSet.eof do begin strTemp := '; for intIndex := 0 to ARecordSet.Fields.count - 1 do strTemp := strTemp + ARecordSet.Fields[intIndex].value+';'; memo1.lines.add( strTemp ); ARecordSet.MoveNext;//移到下条,Next end;
{增加一个记录} ARecordSet.AddNew;//增加,Append ARecordSet.Fields['AName'] := '1';//以FieldByName的方式存取 ARecordSet.Fields['Portable'] := '2'; ARecordSet.Fields(2) := '3';//以Fields[index]的方式存取 ARecordSet.Fields(3) := '4'; ARecordSet.Fields(4) := '5'; ARecordSet.Update;//更新,Post ARecordSet.MoveFirst;//移到首条,First memo1.lines.add('********增加了一条记录后的数据表的内容如下********'); {显示各个域的内容} while not ARecordSet.eof do begin strTemp := '; for intIndex := 0 to ARecordSet.Fields.count - 1 do strTemp := strTemp + ARecordSet.Fields[intIndex].value+';'; memo1.lines.add( strTemp ); ARecordSet.MoveNext;//移到下条,Next end;
{修改最后一条记录} ARecordSet.MoveLast; ARecordSet.Fields['AName'] := '11';//以FieldByName的方式存取 ARecordSet.Fields['Portable'] := '22'; ARecordSet.Fields(2) := '33';//以Fields[index]的方式存取 ARecordSet.Fields(3) := '44'; ARecordSet.Fields(4) := '55'; ARecordSet.Update;//更新,Post ARecordSet.MoveFirst;//移到首条,First memo1.lines.add('********修改了最后一条记录后的数据表的内容如下********'); {显示各个域的内容} while not ARecordSet.eof do begin strTemp := '; for intIndex := 0 to ARecordSet.Fields.count - 1 do strTemp := strTemp + ARecordSet.Fields[intIndex].value+';'; memo1.lines.add( strTemp ); ARecordSet.MoveNext;//移到下条,Next end;
{删除最后一条记录} ARecordSet.MoveLast;//移到末条,Last ARecordSet.delete;//删除,delete ARecordSet.Update;//更新,在Delphi不需要 ARecordSet.MoveFirst;//移到首条,First memo1.lines.add('********删除了最后一条记录后的数据表的内容如下********'); {显示各个域的内容} while not ARecordSet.eof do begin strTemp := '; for intIndex := 0 to ARecordSet.Fields.count - 1 do strTemp := strTemp + ARecordSet.Fields[intIndex].value+';'; memo1.lines.add( strTemp ); ARecordSet.MoveNext;//移到下条,Next end;
ARecordSet.Close;{关闭数据集}
{用SQL语句进行查询,查询姓名为“张三”的记录} {注意,在SQL语句中,字符串应该用单引号包括起来} ARecordSet.open( 'select * from wfjcommu where AName = '张三'', AConnection,adOpenStatic,adLockOptimistic,adCmdText ); memo1.lines.add('********张三的内容如下********'); memo1.lines.add( '共有' + IntToStr( ARecordSet.RecordCount ) + '条匹配的记录' ); {显示各个域的内容} while not ARecordSet.eof do begin strTemp := '; for intIndex := 0 to ARecordSet.Fields.count - 1 do strTemp := strTemp + ARecordSet.Fields[intIndex].value+';'; memo1.lines.add( strTemp ); ARecordSet.MoveNext;//移到下条,Next end;