🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.pascal.delphi.databases
1 messages
1 total messages Started by Fran�ois Delaby Thu, 23 Oct 1997 00:00
Insert : OK. Modify and delete : "Update Failed"
#157
Author: Fran�ois Delaby
Date: Thu, 23 Oct 1997 00:00
181 lines
9561 bytes

--------------47F0FFAB3A5922759B8AA4E7
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Hello.

I use Delphi 3.0 with ODBC and SQL server 6.5.
I have a TQuery wich has a SQL property like that :
  select idf, date
  from mytable
  order by date
I have a second TQuery wich has
  select *
  from mytable
  order by date
The second TQuery has Src1 as DataSource property (Src1 has Query1 as
DataSet property).
When I try to insert a new value in the Query2, all is going well.
When I try to remove or modify a record, it sends a error message :
"Update Failed".

All TQuery CachedUpdate properties are TRUE, RequestLive too.
I have a UpdateRecord procedure like that

procedure TBiologieDtMdl.QueryUpdateRecord(DataSet: TDataSet;
  UpdateKind: TUpdateKind; var UpdateAction: TUpdateAction);
begin
  with (DataSet as TQuery).UpdateObject as TUpdateSQL do
  begin
    SetParams(UpdateKind) ;

// Here, all values seems good
    MessageDlg(FloatToStr((DataSet as
TQuery).FieldByName('Id').AsFloat)+#13+#10+
               FloatToStr(DataSet.FieldByName('Id').NewValue)+#13+#10+
               FloatToStr(DataSet.FieldByName('Id').OldValue)+#13+#10+
               FloatToStr((DataSet as
TQuery).FieldByName('Id_Centre').AsFloat)+#13+#10+

FloatToStr(DataSet.FieldByName('Id_Centre').NewValue)+#13+#10+

FloatToStr(DataSet.FieldByName('Id_Centre').OldValue)+#13+#10+
               DateToStr((DataSet as
TQuery).FieldByName('Date').AsDateTime)+#13+#10+
               DateToStr(DataSet.FieldByName('Date').NewValue)+#13+#10+
               DateToStr(DataSet.FieldByName('Date').OldValue)+#13+#10+
               (DataSet as
TQuery).FieldByName('quantite').AsString+#13+#10+
               DataSet.FieldByName('quantite').NewValue+#13+#10+
               DataSet.FieldByName('quantite').OldValue,
               mtInformation, [mbOk], 0);

    if UpdateKind = ukInsert then
    begin
      Query[UpdateKind].ParamByName('Id_Patient').AsFloat := Id.Idf ;
      Query[UpdateKind].ParamByName('Id_Centre').AsFloat := Id.IdfCentre
;
      Query[UpdateKind].ParamByName('Date').AsDateTime := FDate ;
    end ;

    try

      ExecSQL(UpdateKind) ; // Here, it doesn't work with UpdateKind =
ukModify or ukDelete
    except
      MessageDlg('Impossible de mettre � jour la base', mtError, [mbOk],
0);
      UpdateAction := uaFail ;
      raise ;
    end ;
  end ;
  UpdateAction := uaApplied ;
end;

Any suggestions ?

Fran�ois Delaby.

--------------47F0FFAB3A5922759B8AA4E7
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<HTML>
Hello.

<P>I use Delphi 3.0 with ODBC and SQL server 6.5.<BR>
I have a TQuery wich has a SQL property like that :
<BR>&nbsp; select idf, date
<BR>&nbsp; from mytable
<BR>&nbsp; order by date
<BR>I have a second TQuery wich has
<BR>&nbsp; select *
<BR>&nbsp; from mytable
<BR>&nbsp; order by date
<BR>The second TQuery has Src1 as DataSource property (Src1 has Query1
as DataSet property).
<BR>When I try to insert a new value in the Query2, all is going well.
<BR>When I try to remove or modify a record, it sends a error message :
"Update Failed".

<P>All TQuery CachedUpdate properties are TRUE, RequestLive too.
<BR>I have a <FONT FACE="Arial,Helvetica"><FONT SIZE=-1>UpdateRecord procedure
like that</FONT></FONT><FONT FACE="Arial,Helvetica"><FONT SIZE=-1></FONT></FONT>

<P><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>procedure TBiologieDtMdl.QueryUpdateRecord(DataSet:
TDataSet;</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp; UpdateKind: TUpdateKind;
var UpdateAction: TUpdateAction);</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>begin</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp; with (DataSet as
TQuery).UpdateObject as TUpdateSQL do</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp; begin</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp; SetParams(UpdateKind)
;</FONT></FONT><FONT FACE="Arial,Helvetica"><FONT SIZE=-1></FONT></FONT>

<P><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>// Here, all values seems
good</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp; MessageDlg(FloatToStr((DataSet
as TQuery).FieldByName('Id').AsFloat)+#13+#10+</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
FloatToStr(DataSet.FieldByName('Id').NewValue)+#13+#10+</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
FloatToStr(DataSet.FieldByName('Id').OldValue)+#13+#10+</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
FloatToStr((DataSet as TQuery).FieldByName('Id_Centre').AsFloat)+#13+#10+</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
FloatToStr(DataSet.FieldByName('Id_Centre').NewValue)+#13+#10+</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
FloatToStr(DataSet.FieldByName('Id_Centre').OldValue)+#13+#10+</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
DateToStr((DataSet as TQuery).FieldByName('Date').AsDateTime)+#13+#10+</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
DateToStr(DataSet.FieldByName('Date').NewValue)+#13+#10+</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
DateToStr(DataSet.FieldByName('Date').OldValue)+#13+#10+</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
(DataSet as TQuery).FieldByName('quantite').AsString+#13+#10+</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
DataSet.FieldByName('quantite').NewValue+#13+#10+</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
DataSet.FieldByName('quantite').OldValue,</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
mtInformation, [mbOk], 0);</FONT></FONT><FONT FACE="Arial,Helvetica"><FONT SIZE=-1></FONT></FONT>

<P><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp; if UpdateKind
= ukInsert then</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp; begin</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Query[UpdateKind].ParamByName('Id_Patient').AsFloat := Id.Idf ;</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Query[UpdateKind].ParamByName('Id_Centre').AsFloat := Id.IdfCentre ;</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Query[UpdateKind].ParamByName('Date').AsDateTime := FDate ;</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp; end ;</FONT></FONT><FONT FACE="Arial,Helvetica"><FONT SIZE=-1></FONT></FONT>

<P><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp; try</FONT></FONT><FONT FACE="Arial,Helvetica"><FONT SIZE=-1></FONT></FONT>

<P><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
ExecSQL(UpdateKind) ; // Here, it doesn't work with UpdateKind = ukModify
or ukDelete</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp; except</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
MessageDlg('Impossible de mettre &agrave; jour la base', mtError, [mbOk],
0);</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
UpdateAction := uaFail ;</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
raise ;</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp; end ;</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp; end ;</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>&nbsp; UpdateAction := uaApplied
;</FONT></FONT>
<BR><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>end;</FONT></FONT>

<P>Any suggestions ?

<P>Fran&ccedil;ois Delaby.</HTML>

--------------47F0FFAB3A5922759B8AA4E7--
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads