Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » ElevateDB Technical Support » Product Manuals » ElevateDB Version 2 Manual for RAD Studio 10.4 (Delphi Win64) » Using ElevateDB » Inserting, Updating, and Deleting Rows |
Column # Name DataType Size ---------------------------------------------- 1 CustomerID ftString 10 2 CustomerName ftString 30 3 ContactName ftString 30 4 Phone ftString 10 5 Fax ftString 10 6 EMail ftString 30 7 LastSaleDate ftDate 0 8 Notes ftMemo 0 Index Name Columns In Index Options ---------------------------------------------- Primary_Key CustomerID ixPrimary
begin with MyEDBDataSet do begin Append; { State property will now reflect dsInsert } FieldByName('CustomerID').AsString:='100'; FieldByName('CustomerName').AsString:='The Hardware Store'; FieldByName('ContactName').AsString:='Bob Smith'; FieldByName('Phone').AsString:='5551212'; FieldByName('Fax').AsString:='5551616'; FieldByName('Email').AsString:='bobs@thehardwarestore.com'; Post; { State property will now return to dsBrowse } end; end;
procedure TMyForm.MyTablePostError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); begin Action:=daAbort; if (E is EEDBError) then begin if (EEDBError(E).ErrorCode=EDB_ERROR_CONSTRAINT) then ShowMessage('This row violates a table or column constraint ('+ E.Message+')') else ShowMessage(E.Message); end else ShowMessage(E.Message); end;
begin try with MyEDBDataSet do begin Append; { State property will now reflect dsInsert } FieldByName('CustomerID').AsString:='100'; FieldByName('CustomerName').AsString:='The Hardware Store'; FieldByName('ContactName').AsString:='Bob Smith'; FieldByName('Phone').AsString:='5551212'; FieldByName('Fax').AsString:='5551616'; FieldByName('Email').AsString:='bobs@thehardwarestore.com'; Post; { State property will now return to dsBrowse } end; except on E: Exception do begin if (E is EEDBError) then begin if (EEDBError(E).ErrorCode=EDB_ERROR_CONSTRAINT) then ShowMessage('This row violates a table or column constraint ('+ E.Message+')') else ShowMessage(E.Message); end else ShowMessage(E.Message); end; end; end;
begin with MyEDBDataSet do begin Edit; { State property will now reflect dsEdit } { Set LastSaleDate column to today's date } FieldByName('LastSaleDate').AsDateTime:=Date; Post; { State property will now return to dsBrowse } end; end;
procedure TMyForm.MyTableEditError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); begin Action:=daAbort; if (E is EEDBError) then begin if (EEDBError(E).ErrorCode=EDB_ERROR_LOCKROW) then begin if MessageDlg('The row you are trying to edit '+ 'is currently locked, do you want to '+ 'try to edit this row again?', mtWarning,[mbYes,mbNo],0)=mrYes then Action:=daRetry; end else if (EEDBError(E).ErrorCode=EDB_ERROR_ROWDELETED) then begin MessageDlg('The row you are trying to edit '+ 'has been deleted since it was last '+ 'retrieved',mtError,[mbOk],0); DataSet.Refresh; end else if (EEDBError(E).ErrorCode=EDB_ERROR_ROWMODIFIED) then begin MessageDlg('The row you are trying to edit '+ 'has been modified since it was last '+ 'retrieved, the row will now be '+ 'refreshed',mtWarning,[mbOk],0); DataSet.Refresh; Action:=daRetry; end else MessageDlg(E.Message,mtError,[mbOK],0); end else MessageDlg(E.Message,mtError,[mbOK],0); end;
begin while True do begin try with MyEDBDataSet do begin Edit; { State property will now reflect dsEdit } { Set LastSaleDate column to today's date } FieldByName('LastSaleDate').AsDateTime:=Date; Post; { State property will now return to dsBrowse } end; Break; { Break out of retry loop } except on E: Exception do begin if (E is EEDBError) then begin if (EEDBError(E).ErrorCode=EDB_ERROR_LOCKROW) then begin if MessageDlg('The row you are trying '+ 'to edit is currently locked, '+ 'do you want to try to edit '+ 'this row again?,mtWarning, [mbYes,mbNo],0)=mrYes then Continue; end else if (EEDBError(E).ErrorCode=EDB_ERROR_ROWDELETED) then begin MessageDlg('The row you are trying '+ 'to edit has been deleted '+ 'since it was last retrieved', mtError,[mbOk],0); MyTable.Refresh; Break; end else if (EEDBError(E).ErrorCode=EDB_ERROR_ROWMODIFIED) then begin MessageDlg('The row you are trying '+ 'to edit has been modified '+ 'since it was last retrieved, '+ 'the row will now be '+ 'refreshed',mtWarning,[mbOk],0); MyTable.Refresh; Continue; end else begin MessageDlg(E.Message,mtError,[mbOK],0); Break; end; end else begin MessageDlg(E.Message,mtError,[mbOK],0); Break; end; end; end; end; end;
begin with MyEDBDataSet do Delete; end;
begin with MyEDBDataSet do begin Edit; { State property will now reflect dsEdit } { Set LastSaleDate column to today's date } FieldByName('LastSaleDate').AsDateTime:=Date; Cancel; { State property will now return to dsBrowse } end; end;
begin with MyEDBDataSet do begin Edit; { State property will now reflect dsEdit } { Load a text file from disk } TBlobField(FieldByName('Notes')).LoadFromFile('c:\temp\test.txt'); Post; { State property will now return to dsBrowse } end; end;
var BlobStream: TEDBBlobStream; begin { First create the BLOB stream - be sure to make sure that we put the table into dsEdit or dsInsert mode first since we're writing to the BLOB stream } FirstEDBDataSet.Append; try BlobStream:=TEDBBlobStream.Create(TBlobField( FirstEDBDataSet.FieldByName('TableStream')),bmWrite); try { Now save the table to the BLOB stream } SecondEDBDataSet.SaveToStream(BlobStream); finally { Be sure to free the BLOB stream *before* the Post } BlobStream.Free; end; FirstEDBDataSet.Post; except { Cancel on an exception } FirstEDBDataSet.Cancel; end; end;
This web page was last updated on Thursday, November 16, 2023 at 10:39 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |