Update of the SQL database

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Shouxi Wang

Update of the SQL database

Post by Shouxi Wang » Wed 16 Feb 2005 18:44

I use a DBmemo edit the database record but it always give the following error message when update the database.
"Command text was not set for the command object".
How can I make changes to the database record with the DB aware controls?

Thanks.

Shouxi Wang
Gas Liquids Engineering Ltd.

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Thu 17 Feb 2005 13:34

This error message raises on try to execute an empty query. We cannot tell you something exact without an example.

> How can I make changes to the database record with the DB aware controls?

You can see examples of using DB aware controls in SDAC demos

Guest

Post by Guest » Thu 17 Feb 2005 20:52

Thanks.
I tried the example of SDAC and it works when I set the sql as "Select * from flareReport. If I set the sql as below there will be an error message "Update failed. Found 4 Records" when I made some modification in the linked DBMemo and the sqlFlareRpt update the record.
Thanks again.

AnsiString sql =
"SELECT CAST(Flare + 1 AS smallint) AS [No],\
CAST(TimeStart- 2 AS datetime) AS [Start Time], \
CAST(TimeEnd - 2 AS datetime) AS [End Time], \
DATEDIFF(n, TimeStart, TimeEnd) AS [Duration], \
CAST(FlowMax AS decimal(10, 3)) AS [MaxFlow], \
CAST(FlowMean AS decimal(10, 3)) AS [MeanFlow], \
CAST(FlowTotal AS decimal(10, 3)) AS [Total Volume], \
CAST(H2SMoleP AS decimal(10, 3)) AS [H2S Mole %], \
CAST(H2SMean AS decimal(10, 3)) AS [H2S Mean], \
CAST(H2STotal AS decimal(10, 3)) AS [H2S Flared], \
Reasons \
FROM FlareReport ";

if( flare > 0 || tstart > 0.0 || tend > 0.0 ) {
sql += "WHERE ";
bool hasCondition = false;
if( flare > 0 ) {
hasCondition = true;
sql += "(Flare =" + AnsiString(flare - 1) + AnsiString( ")" );
}
if( tstart > 0.0 ) {
if( hasCondition ) sql += " AND (TimeStart >= " + AnsiString(tstart) + AnsiString( ")" );
else {
hasCondition = true;
sql += " (TimeStart >= " + AnsiString(tstart) + AnsiString( ")" );
}
}
if( tend > 0.0 ) {
if( hasCondition ) sql += " AND (TimeEnd SQL->Count>0) sqlFlareRpt->SQL->Clear();
sqlFlareRpt->SQL->Add( sql );

sqlFlareRpt->Open();
sqlFlareRpt->Edit();

btnOK->Enabled = false;
BitBtn9->Enabled = sqlFlareRpt->RecordCount > 0;

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Fri 18 Feb 2005 10:15

To solve the problem add an unique key field to SELECT.

Guest

Post by Guest » Fri 18 Feb 2005 16:12

IKar,

Thanks. I solved the problem.

Post Reply